Results 1 to 2 of 2

Thread: QTreeWidgetItem* currentItem returns memory address 0x0

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Location
    Rousse, Bulgaria
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTreeWidgetItem* currentItem returns memory address 0x0

    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
    Qt Code:
    1. // Item is a QString that 100% exists on the tree
    2. QTreeWidgetItem *selected = ui->tree->findItems(item,Qt::MatchExactly | Qt::MatchRecursive | Qt::MatchWrap)[0];
    3. selected->setSelected(true); // This selects the node on the tree successfully (visually)
    4. qDebug() << ui->tree->currentItem(); // However this returns 0x0 until I click on the already selected item, then it returns the mem address correctly.
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTreeWidgetItem* currentItem returns memory address 0x0

    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.

Similar Threads

  1. display pointer memory address
    By milosav in forum Qt Programming
    Replies: 8
    Last Post: 2nd February 2016, 08:54
  2. Replies: 3
    Last Post: 26th September 2011, 08:20
  3. Replies: 1
    Last Post: 31st July 2009, 20:03
  4. Cannot access memory at address 0x0
    By defumar in forum Newbie
    Replies: 29
    Last Post: 28th January 2008, 15:55
  5. Compiler's calculation on memory/address
    By vermarajeev in forum General Discussion
    Replies: 3
    Last Post: 10th October 2007, 11:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.