Qt5: QTreeWidget::currentItem() only retuns an item every second call
-
Quite a weird problem. I have a QTreeWidget as a part of a more complex custom widget. I'm trying to get current cursor position by calling currentItem(). This happens when I press a global shortcut key. The problem is that currentItem() only returns an item every 2nd time I press the key, otherwise it returns 0. To make sure it's not something I'm doing to the tree widget, I've set up a timer with 1 second interval that calls this slot:
@void CPanelWidget::onTimer()
{
qDebug() << ui->list->currentItem();
}@And here's what it outputs:
0x0
0x3a88d90
0x0
0x3a88d90
0x0
0x3a88d90
0x0
0x3a88d90
...I didn't press any keys and didn't move or click mouse while the timer was working.
What's wrong?
I've tried digging into Qt sources with debugger, but only figured out that it's caused by currentIndex() returning default-constructed index.