Results 1 to 4 of 4

Thread: Problem editing TreeWidget items

  1. #1
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem editing TreeWidget items

    I have this little program ive been working on for the last week or so and it almost finished but i just cant get the editing function to work.

    I have a tree widget with a couple of items in it. When i select one and hit the edit-button a dialog pops up and asks the user to input two new values. When the ok-button is clicked these values are sent to an edit function which is supposed to edit the selected item.
    It seems like a really easy job, but somehow it does not work. However it workes just fine in another function so i have no idea whats wrong.
    Qt Code:
    1. void MainWindowImpl::button_edit_clicked()
    2. {
    3. // If an item is selected open the dialog
    4. if(treeWidget->currentItem())
    5. {
    6. EditDialog *dialog = new EditDialog;
    7. dialog->show();
    8. }
    9.  
    10. // Edit the selected item
    11. // This one workes fine. Its just a test though
    12. if(treeWidget->currentItem())
    13. {
    14. item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
    15. item->setText(1, "New Date");
    16. treeWidget->insertTopLevelItem(0, item);
    17. }
    18.  
    19. //check
    20. qDebug() << "Edit clicked";
    21. }
    22.  
    23. // the new values are passed to this funktion
    24. void MainWindowImpl::edit_item(QString col0, QString col1)
    25. {
    26.  
    27. // This one does not work, its the same as the same one as above but it produces an error
    28. // When i try to put it inside of a similar if-statementas above, it returns false
    29. // I guess it has something with the selection to do then
    30. item = treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
    31. item->setText(1, "New Date2");
    32. treeWidget->insertTopLevelItem(0, item);
    33.  
    34.  
    35. qDebug() << "Items Recived:" << col0 << col1;
    36. }
    To copy to clipboard, switch view to plain text mode 

    This is the debug message i get:

    Sending Items: "dsa" and "01.Jan 00"
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1224956224 (LWP 8040)]
    0x0804f736 in QTreeWidgetItem::setText (this=0x0, column=1, atext=@0xbf9cadcc) at /usr/include/qt4/QtGui/qtreewidget.h:216
    }
    , alloc = 0
    , size = 0
    , data = 0x8058d92, clean = 0
    , simpletext = 0
    , righttoleft = 0
    , asciiCache = 0
    , capacity = 0
    , reserved = 0
    , array = {0
    }
    }, static shared_empty = {ref = {value = 1
    }
    , alloc = 0
    , size = 0
    , data = 0xb774d44e, clean = 0
    , simpletext = 0
    , righttoleft = 0
    , asciiCache = 0
    , capacity = 0
    , reserved = 0
    , array = {0
    }
    }, d = 0x82db060, static codecForCStrings = 0x0}

    Thanks for your time!
    Last edited by Moezzie; 15th December 2007 at 13:47.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem editing TreeWidget items

    "this=0x0" - you have a null pointer. takeTopLevelItem() probably returns 0.

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem editing TreeWidget items

    Yeah, i kind of figured that out to. I just cant figure out why it would return 0.
    Do you have any suggestions on how to work around it or do it some other way?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem editing TreeWidget items

    Try this:
    Qt Code:
    1. item = treeWidget->currentItem();
    2. item->setText(1, "New Date2");
    3. treeWidget->insertTopLevelItem(0, item);
    To copy to clipboard, switch view to plain text mode 
    The item will be reinserted into the tree properly.

Similar Threads

  1. Problem related to porting from QT3 to QT4 in list items
    By rohitjun in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2007, 09:05
  2. again problem in add items in tablewidget
    By jyoti in forum Qt Tools
    Replies: 3
    Last Post: 24th November 2006, 12:03
  3. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 12:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.