Results 1 to 5 of 5

Thread: QTableView does not show data

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableView does not show data

    My initialization code calls the checkPrefs()
    The view does appear on the desktop.
    Debug statements show that the model has the correct data from the table in the correct database. Debug shows no database errors. 'open' is = "Y" and 'log' is not empty. But, the view on the desktop has no data showing in it.
    What could be wrong?

    Qt Code:
    1. void MainWindow::initializeModel(QSqlTableModel *model) {
    2. model->setTable("log");
    3. model->select();
    4. }
    5.  
    6. QTableView * MainWindow::createView(QString logTitle, QSqlTableModel *model) {
    7. QTableView *view = new QTableView;
    8. view->setModel(model);
    9. view->setWindowTitle(logTitle);
    10. return view;
    11. }
    12.  
    13. void MainWindow::checkPrefs() {
    14. ControlDB ctrl;
    15. QString open = ctrl.getOpenLastLog();
    16. QString log = ctrl.getLastLog();
    17.  
    18. if (open == "Y") {
    19. if (log != "") {
    20. QString logName = log + "_log";
    21. Connection conn;
    22. bool base = conn.createConnection(logName);
    23.  
    24. initializeModel(&model);
    25.  
    26. QTableView *view1= createView(log, &model);
    27. model.select();
    28. view1->show();
    29. }
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QTableView does not show data

    It looks like your QSqlTableModel (line 24) is declared on the stack and goes out of scope before the view gets a chance to do anything with it.

  3. The following user says thank you to ChrisW67 for this useful post:

    waynew (12th December 2009)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView does not show data

    If I put debug lines after the view1->show() I get the following:

    &model is QSqlTableModel(0x22fc10)
    view->model is QSqlTableModel(0x22fc10)

    So shouldn't the model still exist?

    The code I used came almost exactly from a Qt Example, here: http://doc.trolltech.com/4.5/sql-tab...model-cpp.html

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView does not show data

    try this
    Qt Code:
    1. ...
    2. initializeModel(model);
    3.  
    4. QTableView *view1= createView(log, model);
    5. model->select();
    6. view1->show();
    7. ...
    To copy to clipboard, switch view to plain text mode 
    ChrisW67 is right.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following 2 users say thank you to spirit for this useful post:

    formula (27th November 2014), waynew (12th December 2009)

  7. #5
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: QTableView does not show data



    Thanks folks. It works great now.

Similar Threads

  1. how kd chart's data to show tooltip?
    By yunpeng880 in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2009, 07:27
  2. Replies: 1
    Last Post: 23rd November 2008, 15:11
  3. Model/View framework: streaming data in a QTableView
    By yannickt in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2008, 01:06
  4. QTableView - data() - item
    By starcontrol in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 15:41
  5. finding data in a qtableview
    By JeanC in forum Newbie
    Replies: 4
    Last Post: 7th March 2008, 20:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.