Results 1 to 9 of 9

Thread: Help newbie with QTableView...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2008
    Location
    Upper Ferntree Gully, Victoria, Australia
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Help newbie with QTableView...

    Hi folks... firstly let me appologize for such a newbie question.

    I am transitioning from C++ Builder on Windows and am struggling a bit with the way things are done in QT.

    I have a simple form with a QTableView on it and want to display some data from my database in the View.

    I have followed some code from "The Book fo QT4" and have the data coming out of the query OK, but the View remains totally empty.

    The code I'm using is as follows

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    3. {
    4. ui->setupUi(this);
    5.  
    6. QSqlQuery query("select p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareid");
    7. QSqlRecord record = query.record();
    8. while(query.next())
    9. {
    10. //loop
    11. QString res;
    12. res = query.value(record.indexOf("sharename")).toString() + " : ";
    13. res += query.value(record.indexOf("totalvalue")).toString();
    14. qDebug() << query.at() << ": " << res;
    15. }
    16.  
    17. QSqlQueryModel queryModel;
    18. queryModel.setQuery("select p.pricedate, p.valuecol, p.totalvalue, s.sharename from pricedata p inner join shareid s on p.shareid = s.shareid");
    19. if(queryModel.lastError().isValid())
    20. qDebug() << queryModel.lastError();
    21.  
    22. ui->tableView->setModel(&queryModel);
    23. queryModel.setHeaderData(0, Qt::Horizontal, QObject::tr("heading 1"));
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    I know the query is working because the first loop to qDebug is putting out the correct data.

    Now.. I know I'm not doing this correctly and its going to be stupidly easy.. but.. I simply can't work out how to play with widgets that i've put on the main window using QtCreator's GUI maker (or whatever its called).

    Any advice please??

    Thanks

    Peter Nunn
    Last edited by jpn; 15th February 2009 at 11:54. Reason: changed [quote] to [code] tags

Similar Threads

  1. Replies: 3
    Last Post: 29th January 2009, 08:38
  2. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  3. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  4. make QTableView work as a multi-column list view
    By wesley in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2008, 14:43
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.