Results 1 to 8 of 8

Thread: QPSQL: Unable to find table set in a QSqlTableModel

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

    Unhappy QPSQL: Unable to find table set in a QSqlTableModel

    Hi all!

    I'm trying to fetch a record set from a postgreSQL database. Connection to the database was established successfully but when i try to fetch a recordset using a QSqlTableModel i obtain this error: "Unable to find table prod_lotto".
    The table "prod_lotto" exist in the selected database and is correctly initialized.
    Here is the code relative to the QSqlTableModel:
    Qt Code:
    1. ptrProductionModel = new QSqlTableModel(this, currentConnection);
    2. ptrProductionMapper = new QDataWidgetMapper(this);
    3. ptrProductionModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    4. ptrProductionMapper->setModel(ptrProductionModel);
    5.  
    6. // Setup the production table
    7. ptrProductionModel->setTable("prod_lotto");
    8. ptrProductionModel->setSort(lot_number, Qt::AscendingOrder);
    9. ptrProductionModel->setHeaderData(lot_id, Qt::Horizontal, tr("Lot id"));
    10. ptrProductionModel->setHeaderData(lot, Qt::Horizontal, tr("Lot"));
    11. ptrProductionModel->setHeaderData(lot_model, Qt::Horizontal, tr("Lot model"));
    12. ptrProductionModel->setHeaderData(lot_number, Qt::Horizontal, tr("Lot number"));
    13. ptrProductionModel->setHeaderData(customer, Qt::Horizontal, tr("Customer"));
    14. ptrProductionModel->setHeaderData(order_date, Qt::Horizontal, "Order date");
    15. ptrProductionModel->setHeaderData(site, Qt::Horizontal, tr("Site"));
    16. ptrProductionModel->setHeaderData(guarantee_start, Qt::Horizontal, tr("Guarantee start"));
    17. ptrProductionModel->setHeaderData(cabinet_model, Qt::Horizontal, tr("Cabinet model"));
    18. ptrProductionModel->setHeaderData(front_model, Qt::Horizontal, tr("Front model"));
    19. ptrProductionModel->setHeaderData(lot_id, Qt::Horizontal, tr("Lot id"));
    20. ptrProductionModel->setHeaderData(banknote_reader, Qt::Horizontal, tr("Banknote reader"));
    21. ptrProductionModel->setHeaderData(banknote_reader_num, Qt::Horizontal, tr("Banknote reader num."));
    22. ptrProductionModel->setHeaderData(money_reader, Qt::Horizontal, tr("Money reader"));
    23. ptrProductionModel->setHeaderData(money_reader_num, Qt::Horizontal, tr("Money reader num."));
    24. ptrProductionModel->setHeaderData(hopper, Qt::Horizontal, tr("Hopper"));
    25. ptrProductionModel->setHeaderData(hopper_num, Qt::Horizontal, tr("Hopper num."));
    26. ptrProductionModel->setHeaderData(card_dispenser, Qt::Horizontal, tr("Card dispenser"));
    27. ptrProductionModel->setHeaderData(card_dispenser_num, Qt::Horizontal, tr("Card dispenser num."));
    28. ptrProductionModel->setHeaderData(card_system_model, Qt::Horizontal, tr("Card system model"));
    29. ptrProductionModel->setHeaderData(card_system_model_num, Qt::Horizontal, tr("Card system model num."));
    30. ptrProductionModel->setHeaderData(code_card, Qt::Horizontal, tr("Code card"));
    31. ptrProductionModel->setHeaderData(card_release, Qt::Horizontal, tr("Card release"));
    32. ptrProductionModel->setHeaderData(card_release_num, Qt::Horizontal, tr("Card release num."));
    33. ptrProductionModel->setHeaderData(test_date, Qt::Horizontal, tr("Test date"));
    34. ptrProductionModel->setHeaderData(tester, Qt::Horizontal, tr("Tester"));
    35. ptrProductionModel->setHeaderData(notes, Qt::Horizontal, tr("Notes"));
    36. ptrProductionModel->setHeaderData(active_flag, Qt::Horizontal, tr("Active flag"));
    37. ptrProductionModel->setFilter("FLAG_ATTIVO = 1");
    38. ptrProductionModel->select();
    To copy to clipboard, switch view to plain text mode 

    I think that is a problem with QSqlTableModel::setTable function. Can anyone help me?

    Best regards.
    Andrea

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    I don't see anything wrong with the code you posted. Did you properly initialize currentConnection?
    Something like this:
    Qt Code:
    1. QSqlDatabase currentConnection = QSqlDatabase::database("connectionName");
    2. //where connectionName is the string you used in your call to addDatabase()
    To copy to clipboard, switch view to plain text mode 

    Use a qDebug statement to see what database you are operating on:
    Qt Code:
    1. qDebug() << currentConnection.databaseName();
    2. ptrProductionModel = new QSqlTableModel(this, currentConnection);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Last edited by norobro; 17th January 2011 at 05:58. Reason: typo

  3. #3
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Hi norobro.

    currentConnection is properly initialized and database test is going ok. I'm working with PostgreSQL 9.0.2.
    I think that this is a problem relative to the query syntax posted from QPSQL to the database engine. Have you read nothing abount this? Do you know a method to show the last query executed on the database?

    Thanks

  4. #4
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Updates:

    I tried to debug my database stack with a QDebug object and the result are:

    - There is no errors for database connection, it result correctly up and running.
    - There is no errors for the last database transaction executed. Operation required to the QSqlDatabase connection is ok.
    - If i try to execute a QSqlQuery statement with my required query (wroted by hand), it fetch data from PostgreSQL correctly and i can bind all the values in the record.

    My Opnion:
    I think that this is a problem only of the QSqlTableModel stack and for query inserted with model functions. Now i try to give to the model a Query written by hand.

  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Hi Andrea,

    Take a look this bug report.

    My test app worked fine on postgres 8.4 but after upgrading 9.0.1 I got the following warning on the command line: "This version of PostgreSQL is not supported and may not work." Plus lastError() reported "unable to find table foo".

    After applying the patch in the bug report and recompiling the psql driver it works.

    BTW I'm using Qt 4.7.0

    HTH
    Norm

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Quote Originally Posted by andreabiscuola View Post
    I think that this is a problem relative to the query syntax posted from QPSQL to the database engine. Have you read nothing abount this? Do you know a method to show the last query executed on the database?
    QSqlTableModel::selectStatement() should give you the query the model will try to execute.

  7. #7
    Join Date
    Jan 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Hi norobro!

    The bug report you indicated respond completely to my problem! I want to try the patch suggested but i have a doubt: Why the problem appear only using the QSqlTableModel and not with the QSqlQuery?

  8. #8
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QPSQL: Unable to find table set in a QSqlTableModel

    Here is a thread on Qt-interest about this.

    Quote Originally Posted by andreabiscuola View Post
    Why the problem appear only using the QSqlTableModel and not with the QSqlQuery?
    I guess you could dig into the source code to figure out why

Similar Threads

  1. Replies: 1
    Last Post: 3rd February 2010, 07:01
  2. unable to insert into table
    By mohanakrishnan in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2009, 11:52
  3. QSqlRelationalTableModel settable unable to find
    By nietzsche in forum Qt Programming
    Replies: 0
    Last Post: 25th May 2009, 23:51
  4. Can't find QPSQL driver!!
    By brevleq in forum Qt Programming
    Replies: 9
    Last Post: 30th October 2007, 01:29
  5. QPSQL && table change notify
    By Sergey B. in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 16:42

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.