PDA

View Full Version : QTreeWidgetItem* currentItem returns memory address 0x0



Axtroz
22nd July 2012, 10:57
Greetings, I'm trying to make a search form for my QTreeWidget.
My problem is that when the current selection changes it does a database operation to populate a tableview and it crashes.
After a bit of debugging I figured that the problem is that


// Item is a QString that 100% exists on the tree
QTreeWidgetItem *selected = ui->tree->findItems(item,Qt::MatchExactly | Qt::MatchRecursive | Qt::MatchWrap)[0];
selected->setSelected(true); // This selects the node on the tree successfully (visually)
qDebug() << ui->tree->currentItem(); // However this returns 0x0 until I click on the already selected item, then it returns the mem address correctly.

I'm a bit confused why is it happening? The tree emits the signal that the current item changes, but when I attempt to retrieve the new current item it returns an invalid pointer.
Thanks in advance for all replies.

ChrisW67
22nd July 2012, 11:29
The selection and the current item are two different things. Until you set a current item using the mouse, keyboard, or code there is no current item.

Line 2 will crash if there is no match.