Results 1 to 6 of 6

Thread: QTableWidget crashes on setItem

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QTableWidget crashes on setItem

    I everyone,

    I'm trying to fill a QTableWidget with some items, but when trying setItem it segmentation faults.

    Qt Code:
    1. // vLastId is a ID int
    2. // n becomes 2
    3. // query is valid
    4. int n=viewport->db->Count("customer_addresses a,contacts c",
    5. "c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
    6. QSqlQuery query=viewport->db->Select("a.id,a.ragsoc","customer_addresses a,contacts c",
    7. "c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
    8.  
    9. // two columns defined elsewhere
    10. ui.tbwcaddresses->setSortingEnabled(false);
    11. ui.tbwcaddresses->setRowCount(n);
    12. int row=0;
    13. while(query.next())
    14. {
    15. CTableWidgetItem *zid=new CTableWidgetItem(query.value(0).toString());
    16. ui.tbwcaddresses->setItem(row,0,zid); // this row fails and throws exception
    17.  
    18. CTableWidgetItem *iragsoc=new CTableWidgetItem(query.value(1).toString());
    19. ui.tbwcaddresses->setItem(row,1,iragsoc); // this doesn't fail, and seems the same operation!
    20. ...
    21. row++;
    22. }
    23. ui.tbwcaddresses->setSortingEnabled(true);
    To copy to clipboard, switch view to plain text mode 
    If I bypass the excepting row, the second setitem works well.
    I've done this operation tons of times before, but never this problem... What could it be?

    Thank you in advance
    Last edited by Raccoon29; 18th September 2008 at 09:17.
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget crashes on setItem

    did you create a test application for this table and try to insert items?

  3. #3
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTableWidget crashes on setItem

    Quote Originally Posted by spirit View Post
    did you create a test application for this table and try to insert items?
    No I didn't, because I found the fix: there was the usual SLOT called by cellChanged that did controls before it should. Sorry, thank you anyway for your help. It seems like qtcentre air is enhough to solve problems
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  4. #4
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget crashes on setItem

    Quote Originally Posted by Raccoon29 View Post
    No I didn't, because I found the fix: there was the usual SLOT called by cellChanged that did controls before it should. Sorry, thank you anyway for your help. It seems like qtcentre air is enhough to solve problems
    Thank you very much!
    I spent so many time with this crash.

  5. #5
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Wink Re: QTableWidget crashes on setItem

    It's always good to discover to have been helpful even after 5 years!
    You're welcome
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  6. #6
    Join Date
    Aug 2016
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QTableWidget crashes on setItem

    Always helpfull now !

    Thanks a lot !

Similar Threads

  1. Replies: 5
    Last Post: 27th May 2006, 13:44

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.