Assuming you are using Qt Creator. First build your application in debug mode, then start it via F5. Before closing the error dialog, show in the center bottom of creator, and there you will find the - graphical - back trace.
Assuming you are using Qt Creator. First build your application in debug mode, then start it via F5. Before closing the error dialog, show in the center bottom of creator, and there you will find the - graphical - back trace.
er... do u mean this which contains 43 lines? (in the attachment) I can understand nothing within...
as far as what I can see on your picture: in your slot on_treeWidget_it... you are accessing the text() function of an item, but you don't check the pointer to the item if it is not null. My guess. Show us the code of on_treeWidget_it...
Thanx a lot! I see what's wrong. There's a label in the project:
Qt Code:
void MainWindow::on_treeWidget_itemSelectionChanged() { ui->label->setText( ui->treeWidget->currentItem()->text(0) ); }To copy to clipboard, switch view to plain text mode
it just show the name of which is selected. When nothing is available it crashes.
Then I tried this and failed again:
Qt Code:
void MainWindow::on_treeWidget_itemSelectionChanged() { if(ui->treeWidget->topLevelItemCount()>0) ui->label->setText( ui->treeWidget->currentItem()->text(0) ); }To copy to clipboard, switch view to plain text mode
I think when the treeWidget is empty all the members of it are unavailabe. But just how to keep it away from crashing if I still want to use this label?
That is not a valid check! You tree can have items but non must be selected! UseQt Code:
if (ui->treeWidget->currentItem()) ui->label->setText( ui->treeWidget->currentItem()->text(0) ); else ui->label->setText( "No item selected." );To copy to clipboard, switch view to plain text mode
Thanx! Finally it works!
Not a tough problem relly, but has taken me 3 days...
To avoid that and other common errors in future, I strongly suggest you to get familiar with the standard debugging and its output to realize what it is telling your. Just google for "gdb" (GNU debuger) and spend a half day of reading and you will save a lot of time later! And your state of health will also increase
E.g. your problem could have been solved withing 3 minutes (or even faster) without looking at lines which don't cause the problem. And mainly without changing irrelevant code and make it worser...
Bookmarks