Results 1 to 5 of 5

Thread: reading and writing data from a QTableWidget

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default reading and writing data from a QTableWidget

    I need to read data from a file and write its values into a QTableWidget. I programm this:

    TBLiradopts->insertRow(row);
    TBLiradopts->item(row,col)->setText(qv);

    where qv is the datavalue (Qstring), row and col change (in a loop).

    But I obtained an error

    Excepción no controlada en 0x6541ab55 (QtGuid4.dll) en QTDAM.exe: 0xC0000005: Infracción de acceso al leer la ubicación 0x00000000.

    And point to this:

    inline void QTableWidgetItem::setText(const QString &atext)
    { setData(Qt:isplayRole, atext); }

    What's the problem?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading and writing data from a QTableWidget

    Probably you try to dereference a null pointer.

    Most likely here:
    Qt Code:
    1. TBLiradopts->item(row,col)->setText(qv);
    To copy to clipboard, switch view to plain text mode 
    Check whether item() doesn't return 0.

  3. #3
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: reading and writing data from a QTableWidget

    I have change the code and works but I dont know why:

    TBLiradopts->insertRow(row);
    QTableWidgetItem *newItem=new QTableWidgetItem(row*col);
    newItem->setText(qv);
    TBLiradopts->setItem(row,col,newItem);

    do you know why, because row and col have the same values (in my last post)?

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reading and writing data from a QTableWidget

    Quote Originally Posted by zorro68 View Post
    do you know why, because row and col have the same values (in my last post)?
    The docs say:
    QTableWidgetItem * QTableWidget::item ( int row, int column ) const
    Returns the item for the given row and column if one has been set; otherwise returns 0.
    See also setItem().
    Have you set a QTableWidgetItem for given row and column before trying to access it through item()?

  5. #5
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: reading and writing data from a QTableWidget

    No. I think that is the problem.

    Thanks for your quick answer.

Similar Threads

  1. Replies: 6
    Last Post: 8th January 2007, 10:24
  2. Replies: 6
    Last Post: 27th February 2006, 12:47
  3. reading in image from 24bit char*
    By cbeall1 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2006, 00:09

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.