Results 1 to 12 of 12

Thread: QTableView sorting problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Apr 2008
    Posts
    5
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView sorting problem

    Thank you Janus, but this do not sove my problem...

    A compilable code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QSqlDatabase>
    3. #include <QSqlQuery>
    4. #include <QString>
    5. #include <QSqlTableModel>
    6. #include <QTableView>
    7. #include <QtGui>
    8. #include <QtSql>
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. //QWidget *w = new QWidget;
    15.  
    16. QTableView * tableView = new QTableView();
    17.  
    18. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    19. db.setDatabaseName("stock.sqlite");
    20. if (!db.open()) QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
    21.  
    22. model = new QSqlTableModel(tableView);
    23. model->setTable("productes");
    24. model->select();
    25. tableView->setSortingEnabled(true);
    26. tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    27. tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    28. tableView->setModel(model);
    29.  
    30. db.close();
    31. tableView->show();
    32. //w->show();
    33. return app.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

    this can be tried with the database attached (it is very small), i put the .txt extension to upload it, but it is in sqlite3 format.

    I was trying (for one week) to use a mysql database, but I can't compile the driver, I know that are lots of threads and lots of tutorials, but I always get a compile error, is there a really working way to compile/load the mysql driver?
    Attached Files Attached Files

Similar Threads

  1. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  2. Problem with QTableView
    By BoneCollector in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 12:30
  3. Slow problem QTableView
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 26th February 2008, 12:19
  4. problem in printing QTableView
    By miguel_mark in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 08:19
  5. Sorting QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 7
    Last Post: 9th February 2006, 16:47

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.