Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Set model not working!!
Forum Updated to NodeBB v4.3 + New Features

Set model not working!!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aurora
    wrote on last edited by
    #1

    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)));
    }
     
    }@
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aurora
        wrote on last edited by
        #3

        Thank u ...:) ya that was the silly mistake...:P

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          It happens from time to time :-)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veeraps
            wrote on last edited by
            #5

            Would you update the subject with prefix [SOLVED]?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved