I am new to Qt and wanted to execute something if my treeWidget is empty.
I tried topLevelItemCount, but that didnt work;
if (treeWidget_2->topLevelItemCount() == 0) {
//this doesn't even get executed.
}
I get a segfault when doing that. I'm completely sure its because of toplevelCount, because I went through it with the debugger.
BTW: My TreeWidget isn't empty. It has one item and this has one subitem
treeWidet
|-----test
|---test
I also followed this tutorial and created a function treeCount:
int MainWindow::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0) //counts the nodes inside a specific tree
{
int count = 0;
if (parent == 0) {
int topCount = tree->topLevelItemCount();
for (int i = 0; i < topCount; i++) {
QTreeWidgetItem *item = tree->topLevelItem(i);
}
count += topCount;
} else {
int childCount = parent->childCount();
for (int i = 0; i < childCount; i++) {
QTreeWidgetItem *item = parent->child(i);
}
count += childCount;
}
return count;
}
I changed it a little bit to fit my needs. No problem there. The real struggle is this error message:
default argument given for parameter 3 of 'int blablabla' [-fpremissive]
int MainWindow::treeCount(QTreeWidget *tree, QTreeWidgetItem *parent = 0)
^
I'm using Qt 5.7 on Linux. (GNOME, if that matters)
As I am a total newb to Qt, I might have forgotten something important. feel free to ask for it ;)