Results 1 to 3 of 3

Thread: QTableWidgetItem setData crashes everytime.

  1. #1
    Join Date
    Mar 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default QTableWidgetItem setData crashes everytime.

    Hi at all,
    I'm trying to simply set a QString in a QTableWidgetItem.

    Qt Code:
    1. ui->tableWidget->item(0,0)->setData(Qt::DisplayRoleRole,"foo");
    To copy to clipboard, switch view to plain text mode 

    But when I do this the little app crashes.

    Instead, if I write something before in the same cell by myself, the setData works out.

    It sounds like the item object isn't still created when I try to setData. When I before write something in the same cell trought the GUI, the object is created and the the setData istruction works.

    Any Idea? that's real strange.

    Sorry for my english

    Gianluigi
    Last edited by Wing_Zero; 16th August 2010 at 14:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTableWidgetItem setData crashes everytime.

    It's not strange at all. ui->tableWidget->item(0,0) will return a null pointer, and this is the reason why you app crashes. You first have to add the items, then you can alter it. And by the way better always check the validity of a pointer before using it.

  3. #3
    Join Date
    Mar 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QTableWidgetItem setData crashes everytime.

    Thanks for your answer!
    Sorry for the maybe stupid question, but i'm new to Qt.
    How can I Add an Item?
    The only way it is to create an Item and then add to the QTableWidget with the SetItem method?
    There's no faster way?

    And, after that, if I had to create an item by myself, what is the difference between the cells and items?

    Thanks in advance.

    Gianluigi

Similar Threads

  1. QTableWidgetItem: setData or setText?
    By mattc in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2010, 18:34
  2. QSqlTableModel and possible bug with setData?
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2009, 21:43
  3. update() works fine sometime but not everytime..!!
    By salmanmanekia in forum Qt Programming
    Replies: 19
    Last Post: 22nd August 2008, 09:11
  4. setData()
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 08:54
  5. setData()
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2008, 12:51

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.