Results 1 to 4 of 4

Thread: QSqlTableModel select() fails with QODBC connection to SQL Express?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    United States
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlTableModel select() fails with QODBC connection to SQL Express?

    EDIT: The skinny version is I need to know if this is supported with freeTDS ODBC drivers. If not I'd appreciate any open source unix ODBC driver recommendation that will play nice with QT

    First I'm using QT 4.6.2 on Ubuntu. My test app connects through freeTDS odbc to a SQL Server Express instance running on a Windows 7 machine. Now I can connect and run queries just fine with this setup under normal circumstances using QT.

    I recently decided to play with using QSqlTableModel to display the results of a query in a QTableView however I ran into some odd behavior. It appears the select() method is failing because the query syntax is incorrect. The query appears to be missing the column names which means the setTable method failed to retrieve the field information correctly although it does seem to know there are 3 columns in the table judging by the commas generated despite the empty strings.

    Code Snippet:
    Qt Code:
    1. void MainWindow::on_pbFetch_clicked()
    2. {
    3. //ZDataTable* results = new ZDataTable(myDB->FetchSQL(ui->txtQuery->toPlainText()));
    4.  
    5. // TEST CASE
    6. QSqlTableModel* results = new QSqlTableModel(this, *myDB);
    7. results->setTable("SystemConfig"); // fails to get fields correctly
    8. results->setEditStrategy(QSqlTableModel::OnManualSubmit);
    9.  
    10. if (!results->select())
    11. {
    12. QMessageBox::critical(this, "Error", results->lastError().text());
    13. QMessageBox::information(this, "Query", results->query().lastQuery());
    14. }
    15.  
    16. results->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
    17. results->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
    18. results->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
    19.  
    20. QTableView* view = InitDBView(results);
    21. view->show();
    22. // END TEST CASE
    23. }
    24.  
    25. QTableView* MainWindow::InitDBView(QSqlTableModel* model)
    26. {
    27. QTableView* view = new QTableView;
    28. view->setModel(model);
    29. view->setWindowTitle("Result Table");
    30. return view;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Here is the screen cap of the message boxes from above showing the error and the attempted query:



    My question is this a limitation because I'm using SQL Server Express through ODBC, a bug with QT, or something I'm doing wrong in my code?
    Last edited by ajg85; 6th April 2010 at 21:02.

Similar Threads

  1. QSqlDatabase::open() fails with QODBC
    By grzywacz in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2010, 03:27
  2. QSqlTableModel::select()
    By vladozar in forum Qt Programming
    Replies: 4
    Last Post: 29th April 2009, 17:51
  3. Queued connection fails on own class
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 2nd December 2008, 18:50
  4. QODBC, QSqlTableModel, and submit problems
    By darkadept in forum Qt Programming
    Replies: 3
    Last Post: 18th May 2008, 12:46
  5. Qt 4 commercial with Visual C++ 2005 Express Edition: Works half, debug fails
    By axeljaeger in forum Installation and Deployment
    Replies: 4
    Last Post: 5th July 2006, 05:38

Tags for this Thread

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.