Results 1 to 1 of 1

Thread: QTableView displays column headers, but no data?

  1. #1
    Join Date
    Jan 2015
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTableView displays column headers, but no data?

    Edit: I think this is solved, appears to be a qt or qt designer bug -- see bottom of post...



    I can't figure out why my QTableView won't display any data. I've searched all other questions about this problem and it seems the problem is usually someone trying to create the model on the stack and letting it go out of scope...

    I am creating the model on the heap so this is not the problem, yet I still get no data in the View. The column headers from my sql table ARE shown correctly in the view. What could be wrong with this code?
    Qt Code:
    1. // db is my database wrapper and database() returns a reference to the database
    2. QSqlTableModel *tradeHistoryModel = new QSqlTableModel(this, db->database());
    3.  
    4. // table_tradeHistory is my QTableView created elsewhere
    5. table_tradeHistory->setModel(tradeHistoryModel);
    6.  
    7. tradeHistoryModel->setTable("mytrades");
    8. tradeHistoryModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    9.  
    10. if (!tradeHistoryModel->select())
    11. {
    12. // err is just a handy macro for displaying fancy error output
    13. // the call to select does NOT return false so this never gets called
    14. err("model select failed!");
    15. }
    16.  
    17. // debug is another macro, the output shows 200 rows (which is correct)
    18. debug(QString("Got %1 rows..").arg(tradeHistoryModel->rowCount()));
    To copy to clipboard, switch view to plain text mode 
    So there is no error shown because select() returns true, and the debug output shows the model selected all 200 rows, but still no data appears in the View...

    As far as I can tell from examples this code should work. Is there some property of QTableView or QSqlTableModel that could be causing the problem?

    Thanks for any help!

    Edit: I should probably mention this is on qt5

    Edit: This must have been a Qt or Qt Designer bug... I went back into designer and "morphed" the QTableView into a QTreeView, then switched it back and now all of a sudden it is showing the data... I did not change any of the code when I did this... wtf? If it is a bug I'm not sure I can reproduce it again...
    Last edited by artephius; 10th March 2015 at 00:40.

Similar Threads

  1. Replies: 4
    Last Post: 27th February 2014, 10:42
  2. How to get all column data of a QTableView
    By npascual in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2012, 10:05
  3. Replies: 3
    Last Post: 9th May 2011, 18:23
  4. QTableView column-headers too short ...
    By kerim in forum Newbie
    Replies: 2
    Last Post: 20th April 2011, 10:09
  5. QTableView + column span of headers
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 15:29

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.