PDA

View Full Version : QTableWidget



kishore7771
6th October 2009, 06:10
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........

yogeshgokul
6th October 2009, 06:19
Please create the QTableWidgetItem in heap instead of stack. Like this :

for (int row=0;row<tableWidget.rowCount(); row++)
for (int col=0;col<tableWidget.columnCount(); col++)
{
QTableWidgetItem *item = new QTableWidgetItem("ABC");
tableWidget.setItem(row, col,item);
}

kishore7771
6th October 2009, 06:25
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

yogeshgokul
6th October 2009, 06:46
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.