Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5: QTreeWidget::currentItem() only retuns an item every second call
Qt 6.11 is out! See what's new in the release blog

Qt5: QTreeWidget::currentItem() only retuns an item every second call

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 956 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved