Results 1 to 3 of 3

Thread: setData problem at QStandardItemModel first visible item!!!

  1. #1
    Join Date
    Sep 2011
    Posts
    30
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default setData problem at QStandardItemModel first visible item!!!

    Hi,
    I have created a QStandardItemModel for QTreeView and will update some item's data when some data changed. Everything is ok except when set data to the first visible item, it will cause the program exit in abnormal. the code as below:
    Qt Code:
    1. QString tag = tagitem->data(Qt::DisplayRole).toString();
    2. if (tag == QString("Width") || tag == QString("Height"))
    3. {
    4. QString val = item->data(Qt::DisplayRole).toString();
    5. int t = QLocale().toInt(val);
    6. QRectF rect = panel->rect();
    7. if (tag == QString("Width")) rect.setWidth(t);
    8. else rect.setHeight(t);
    9. panel->setRect(rect);
    10.  
    11. QString s = QLocale().toString(rect.width()) +
    12. QString("x") +
    13. QLocale().toString(rect.height());
    14.  
    15. rootItems.at(1)->setData(s, Qt::DisplayRole);
    16.  
    17. qDebug() << rootItems.at(0)->data(Qt::DisplayRole).toString() << ":" << rootItems.at(1)->data(Qt::DisplayRole).toString();
    18. scene->update();
    19. }
    To copy to clipboard, switch view to plain text mode 
    I just want to update the panel data (1920x1080) according panel's width or height change. I'm sure rootItems.at(1) is pointed to the data (1920x1080), please see below picture,
    error.png

    anyone has suggestion? thanks.

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

    Default Re: setData problem at QStandardItemModel first visible item!!!

    Which line causes the crash? Your debugger will tell you. Without that information I would guess: one or more of the tagItem, item, panel, scene, or rootItems.at(0 or 1) pointers are null or invalid. Possibly rootItems contains less than two entries, which would also be a bad thing.

  3. #3
    Join Date
    Sep 2011
    Posts
    30
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: setData problem at QStandardItemModel first visible item!!!

    Thanks for reply. The crash caused by line 15, but I'm sure rootItems contains 2 entries because if I remove line 15, line 16 can work well and output follow message:
    "Panel" : "1920x1080"
    It means rootItems.at(1) has the initial data "1920x1080". Please help to analysis again, thanks.

Similar Threads

  1. QListView item with border 0 still visible
    By Erazem in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 3rd September 2010, 16:16
  2. Replies: 1
    Last Post: 22nd February 2010, 10:53
  3. Replies: 2
    Last Post: 11th January 2010, 11:39
  4. Replies: 2
    Last Post: 7th December 2009, 14:15
  5. QStandardItemModel save/load Problem
    By sun in forum Newbie
    Replies: 9
    Last Post: 1st October 2008, 18:20

Tags for this Thread

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.