Results 1 to 3 of 3

Thread: Problem inserting in QTableWidget

  1. #1
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem inserting in QTableWidget

    Hi All,

    I have a QTableWidget that I add rows during runtime using the following type of code:
    Qt Code:
    1. bool QTClient::addToTable (int id, int lobby_view, QString name)
    2. {
    3. int column = 0;
    4.  
    5. ui.m_TableWidget->insertRow(ui.m_TableWidget->rowCount ());
    6.  
    7. QTableWidgetItem* tbl_item = new QTableWidgetItem (QString::number(id));
    8. ui.m_TableWidget->setItem ( location_index, column++, tbl_item );
    9.  
    10. tbl_item = new QTableWidgetItem (QTableWidgetItem (QString::number(lobby_view)));
    11. ui.m_TableWidget->setItem ( location_index, column++, tbl_item );
    12.  
    13. tbl_item = new QTableWidgetItem (QTableWidgetItem (name));
    14. ui.m_TableWidget->setItem ( location_index, column++, tbl_item );
    15.  
    16. ui.m_holdemAllTableWidget->update ();
    17. }
    To copy to clipboard, switch view to plain text mode 

    I have a button on my window that calls this code when pressed and the new line is added and displayed just fine in the table.

    However, the problem comes when this add method is called from a thread.
    When my thread fires it also calls the addTable method, but the data does not show up on the screen. The row count on the table increases, but the new data does not display.

    Does anyone have any ideas why I can not see data added to my table from a thread?

    Thanks in advance,
    Derrick

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

    Default Re: Problem inserting in QTableWidget

    Quote Originally Posted by DPinLV
    Does anyone have any ideas why I can not see data added to my table from a thread?
    You can't invoke widget methods from a non-GUI thread (see here). To do it the right way, you have to turn addToTable() into a slot and use a queued connection.

  3. #3
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem inserting in QTableWidget

    Jacek,

    That explains a lot... I've been doing some more research and I'll be making another posting because my signal slot works using a simple type (i.e. int, QString, etc.), but the connect call fails when I pass my custom struct.

    Thanks,
    Derrick

Similar Threads

  1. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  2. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  3. Replies: 16
    Last Post: 7th March 2006, 16:57
  4. Replies: 6
    Last Post: 5th March 2006, 22:05
  5. Problem with inserting text into QTextEdit
    By xorrr in forum Qt Programming
    Replies: 0
    Last Post: 6th February 2006, 12:45

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.