Results 1 to 4 of 4

Thread: Set model not working!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    31

    Default 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....



    Qt Code:
    1. void win::on_pushButton_clicked()
    2. {
    3.  
    4. QStringList signalList;
    5. QString filename;
    6. filename="C:/Users/Desktop/abc.txt";
    7. headersList=GetheaderNames(filename);
    8.  
    9. QFileInfo file(filename);
    10. createTable(file.baseName(),headersList);
    11. GetFileContent(filename);
    12. QSqlQueryModel plainModel2;
    13. initializeModel(&plainModel2,file.baseName(),headersList);
    14.  
    15. ui->tableView_2->setModel(&plainModel2);
    16. }
    To copy to clipboard, switch view to plain text mode 



    initialiseModel function
    Qt Code:
    1. void initializeModel(QSqlQueryModel *model,QString filename, QStringList headersList)
    2. {
    3. QString queryString=QString("select * from %1").arg(filename);
    4.  
    5. model->setQuery(queryString);
    6. for(int i=0;i<headersList.count();i++)
    7. {
    8. model->setHeaderData(i, Qt::Horizontal, (headersList.at(i)));
    9. }
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 


    plz help me to sort out the problm here!!

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Set model not working!!

    You are creating the model on stack, which will not work in your case, as it will go out of scope after on_pushButton_clicked(0 is exited.

    Create the model on heap.

    QSqlQueryModel* plainModel2 = new QSqlQueryModel(...)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. custom table model is not working
    By aurora in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2012, 20:02
  3. Filtering "NoDotDot" in filesystem model not working
    By aurora in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2012, 10:02
  4. Replies: 1
    Last Post: 13th June 2008, 18:58
  5. Help with getting my custom model working
    By thomaspu in forum Qt Programming
    Replies: 19
    Last Post: 29th July 2007, 18:35

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
  •  
Qt is a trademark of The Qt Company.