Results 1 to 4 of 4

Thread: QTableWidget

  1. #1
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableWidget

    HI ,

    i am trying to diaplay data in QTablewidget like this ..


    #include <QtGui>
    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);
    QTableWidget tableWidget(3,3);

    for (int row=0;row<tableWidget.rowCount(); row++)
    for (int col=0;col<tableWidget.columnCount(); col++)
    {
    QTableWidgetItem item;
    item.setText(QString("ABC"));
    tableWidget.setItem(row, col,&item);
    }
    tableWidget.show();
    return app.exec();
    }
    It is not displaying any data.
    But when i placed this data in above for loop it is crashing.

    Please help me........

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget

    Please create the QTableWidgetItem in heap instead of stack. Like this :
    Qt Code:
    1. for (int row=0;row<tableWidget.rowCount(); row++)
    2. for (int col=0;col<tableWidget.columnCount(); col++)
    3. {
    4. QTableWidgetItem *item = new QTableWidgetItem("ABC");
    5. tableWidget.setItem(row, col,item);
    6. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to yogeshgokul for this useful post:

    kishore7771 (6th October 2009)

  4. #3
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget

    Hi
    This is the sample code,
    In actual code i need to display around 7 lakh records ..
    If i use new after displaying around 1 lakh records it is crashing...
    It is taking huge amount of time to display...
    Instead of QTableWidget any other control is there....


    Thanks in Advance

  5. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget

    Then you need MVC power of Qt. Do not load all records at once, load them in thread. And do some caching.
    For that you can use QTableView.

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 15:15
  3. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.