Results 1 to 5 of 5

Thread: QSqlQueryModel and QTableView question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2006
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    5

    Question QSqlQueryModel and QTableView question

    Hello.
    I am a newbie.

    here is part of my code:

    trans.h
    Qt Code:
    1. #ifndef TRANS_H
    2. #define TRANS_H
    3.  
    4. #include <QtSql>
    5. #include "ui_fleTrans.h"
    6.  
    7. class trans : public QWidget, private Ui::frmTrans
    8. {
    9. Q_OBJECT
    10. public:
    11. trans(QWidget *parent = 0);
    12.  
    13. public slots:
    14. ...
    15. void showTable(QSqlQueryModel *model);
    16. void initializeModel(QSqlQueryModel *model);
    17. ...
    18.  
    19. private:
    20. ...
    21. };
    22. #endif
    To copy to clipboard, switch view to plain text mode 

    trans.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. #include "trans.h"
    4. #include "custsqlmodel.h" //basically the same as customsqlmodel in sql/querymodel
    5. //example
    6.  
    7. trans::trans(QWidget *parent)
    8. {
    9. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    10. db.setHostName("localhost");
    11. db.setDatabaseName("databasename");
    12. db.setUserName("username");
    13. db.setPassword("password");
    14. if (!db.open())
    15. {
    16. QMessageBox::critical(0, "Database Error", db.lastError().text());
    17. }
    18.  
    19. setupUi(this);
    20.  
    21. model = new QSqlQueryModel;
    22.  
    23. CustSqlModel custSqlModel;
    24. initializeModel(&custSqlModel);
    25. showTable(&custSqlModel);
    26. }
    27.  
    28. void trans::initializeModel(QSqlQueryModel *model)
    29. {
    30. model->setQuery("select * from table");
    31. }
    32.  
    33. void trans::showTableLedger(QSqlQueryModel *model)
    34. {
    35. QTableView *view = new QTableView;
    36. view->setModel(model);
    37. view->show();
    38. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "trans.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. trans *dialog = new trans;
    8. dialog->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    nothing wrong with my qsqlquerysublcass since it compiles without error and shows the data in the table using the sql/querymodel example.

    The above code simply shows a window frame with scroll bars, no grid, no column header, no data - just white space.

    Please help.

    Thank you in advance.

    wil
    Last edited by jacek; 20th September 2006 at 15:40. Reason: missing [code] tags

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 18:13
  2. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 07:17

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.