Set model not working!!
-
I am using QSqlQuerModel in my program and using table view to display the contents of the model.
But when i set the model nothing displays in the table other than two brown lines at the horizontal and verticla headers.....
my program code....
@ void win::on_pushButton_clicked()
{QStringList signalList; QString filename; filename="C:/Users/Desktop/abc.txt"; headersList=GetheaderNames(filename); QFileInfo file(filename); createTable(file.baseName(),headersList); GetFileContent(filename); QSqlQueryModel plainModel2; initializeModel(&plainModel2,file.baseName(),headersList); ui->tableView_2->setModel(&plainModel2); }@
initialiseModel function
@
void initializeModel(QSqlQueryModel *model,QString filename, QStringList headersList)
{
QString queryString=QString("select * from %1").arg(filename);model->setQuery(queryString); for(int i=0;i<headersList.count();i++) { model->setHeaderData(i, Qt::Horizontal, (headersList.at(i))); } }@
-
Your plainModel2 is created on the stack. It is destroyed as soon as you leave the method. You will have to create it on the heap using new.
-
Thank u ...:) ya that was the silly mistake...:P
-
It happens from time to time :-)
-
Would you update the subject with prefix [SOLVED]?