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;
    QFileInfo file(filename);
    QSqlQueryModel plainModel2;

    initialiseModel function
    void initializeModel(QSqlQueryModel *model,QString filename, QStringList headersList)
    QString queryString=QString("select * from %1").arg(filename);

    for(int i=0;i<headersList.count();i++)
    model->setHeaderData(i, Qt::Horizontal, (;

  • 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]?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.