Results 1 to 12 of 12

Thread: Problem wit 2010.01

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Problem wit 2010.01

    Hello friends,

    after deinstall 2009.05 and install 2010.01 the qsqltabelmodel in combination with qtableview is still empty. My local Sqlite DB, which I use in my program is fullfilled correct, afterwards I show it in a QTabelview with my QSqlTableModel, but it shows nothing my view is still emty
    and model->select() returns false. Have anybody the same problem?? With the 2009.05 everything was ok???

  2. #2
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    So in addition I do some tests.:

    Qt Code:
    1. db = QSqlDatabase::database("LocalDB");
    2. qDebug() << "LocalDB is Valid?:"<< db.isValid();
    3. QSqlQuery mytest("select * from localDBtable",db);
    4.  
    5. while(mytest.next())
    6. {
    7. qDebug() << mytest.value(2).toString() << endl;
    8. }
    9.  
    10. QSqlTableModel mymodel;
    11. mymodel.setTable("localDBtable");
    12. bool loctest = mymodel.select();
    To copy to clipboard, switch view to plain text mode 
    So first of all I test the db validation here I get a <true> value
    The second I test, if I could trace over a select statement from the table. An I get the value in the while loop. So everything seems ok.
    Last I take a QSqlTableModel and try to select() the table, but I get an <false> value.

    So I am at the end of my knowledge?
    Could anybody image what wrong here???

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem wit 2010.01

    Did you initialize the database driver properly using QSqlDatabase::addDatabase()? Can we see the exact call?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Dec 2009
    Location
    Brisbane
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem wit 2010.01

    could you also supply us with the lastError() on the model (after the select?)

    Qt Code:
    1. if(!loctest)
    2. qDebug() << mymodel().lastError();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    @wysota
    I have header file with static methods:
    Qt Code:
    1. /**
    2.  * Static function for databse connection;
    3.  */
    4. //**************************************************************************
    5. static bool createConLocalDb()
    6. //**************************************************************************
    7. {
    8. QString dbpath;
    9. dbpath = QCoreApplication::applicationDirPath();
    10. dbpath.append("/");
    11. dbpath.append("../db/localdb.db");
    12. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE","LocalDB");
    13. db.setDatabaseName(dbpath);
    14. if (!db.open())
    15. {
    16. QMessageBox::critical(0, qApp->tr("Cannot open database localdb"),
    17. qApp->tr("Unable to establish a database connection.\n"
    18. "This example needs SQLite support. Please read "
    19. "the Qt SQL driver documentation for information how "
    20. "to build it.\n\n"
    21. "Click Cancel to exit."), QMessageBox::Cancel);
    22. return false;
    23. }
    24. qDebug() << "SQLITE LocalDB" << db.driver();
    25. qDebug() << "SQLITE LocalDB" << db.driverName();
    26. qDebug() << "SQLITE LocalDB" << db.connectionName();
    27. return true;
    28. }
    29.  
    30.  
    31. //**************************************************************************
    32. static bool createConDB2(QString driver= "QODBC",
    33. QString connectionstr="DRIVER={SQL Server Native Client 10.0};"
    34. "Server=locationToserver;Trusted_Connection=no;"
    35. "Database=mydatabasename;Uid=myuid;Pwd=mypass"
    36. )
    37. //**************************************************************************
    38. {
    39. QSqlDatabase db = QSqlDatabase::addDatabase(driver,"DB2");
    40. db.setDatabaseName(connectionstr);
    41. if (!db.open()) {
    42. QSqlError err = db.lastError ();
    43. QMessageBox::information(0, QObject::tr("Cannot open database DB2"), err.text());
    44. return false;
    45. }
    46. qDebug() << "MSSQL DB2" << db.driver();
    47. qDebug() << "MSSQL DB2" << db.driverName();
    48. qDebug() << "MSSQL DB2" << db.connectionName();
    49. return true;
    50. }
    51.  
    52.  
    53. //**************************************************************************
    54. static bool createConDummy()
    55. //**************************************************************************
    56. {
    57. QString dbpath;
    58. dbpath = QCoreApplication::applicationDirPath();
    59. dbpath.append("/");
    60. dbpath.append("../db/dummydb.db");
    61. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    62. db.setDatabaseName(dbpath);
    63. if (!db.open())
    64. {
    65. QMessageBox::critical(0, qApp->tr("Cannot open database dummy"),
    66. qApp->tr("Unable to establish a database connection.\n"
    67. "This example needs SQLite support. Please read "
    68. "the Qt SQL driver documentation for information how "
    69. "to build it.\n\n"
    70. "Click Cancel to exit."), QMessageBox::Cancel);
    71. return false;
    72. }
    73. qDebug() << "SQLITE Dummy" << db.driver();
    74. qDebug() << "SQLITE Dummy" << db.driverName();
    75. qDebug() << "SQLITE Dummy" << db.connectionName();
    76. return true;
    77.  
    78. }
    To copy to clipboard, switch view to plain text mode 

    After in the constructor I made this:

    Qt Code:
    1. this->createStatusBar();
    2. qDebug() << " Creating Connections to Databases";
    3. int i_conDummy=createConDummy();//"qt_sql_default_connection"
    4. int i_conlocaldb = createConLocalDb();//"LocalDB"
    5. int i_conMssql = createConDB2();//"DB""
    6. ...
    7. ...
    To copy to clipboard, switch view to plain text mode 
    The integer values after connection are changed to '1';

    After connections to my databses I have this output for the static method I call:

    Qt Code:
    1. Creating Connections to Databases
    2. SQLITE Dummy QSQLiteDriver(0x9fff208)
    3. SQLITE Dummy "QSQLITE"
    4. SQLITE Dummy "qt_sql_default_connection"
    5. SQLITE LocalDB QSQLiteDriver(0xa000548)
    6. SQLITE LocalDB "QSQLITE"
    7. SQLITE LocalDB "LocalDB"
    8. MSSQL Proleas QODBCDriver(0xa0016e0)
    9. MSSQL Proleas "QODBC"
    10. MSSQL Proleas "DB2"
    To copy to clipboard, switch view to plain text mode 


    @tangential

    could you also supply us with the lastError() on the model (after the select?)
    This is the output:

    Qt Code:
    1. Last Error: QSqlError(1, "Unable to execute statement", "near ",": syntax error")
    To copy to clipboard, switch view to plain text mode 

    @all

    with the mssql database I don´t have this select() problem on the modelside !

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem wit 2010.01

    And how does the main() function look like?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    Qt Code:
    1. #include <QApplication>
    2. #include <QCoreApplication>
    3. #include <QMainWindow>
    4.  
    5. #include "../headers/tableeditor.h"
    6.  
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11. Q_INIT_RESOURCE(myresourcefile);
    12. TableEditor editor;
    13. editor.showMaximized();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    This is my main.cpp

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem wit 2010.01

    So where do you create those connections? Also please inject the following code after each statement of the code you pasted in post #5 of this thread that operates on the database (creates it, queries it, operates on an sql model) and show us results:
    Qt Code:
    1. qDebug() << db.lastError().text();
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2010
    Posts
    5
    Thanked 7 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem wit 2010.01

    I think you should init your model like this
    Qt Code:
    1. QSqlTableModel *model = new QSqlTableModel(this, QSqlDatabase::database("LocalDB"));
    To copy to clipboard, switch view to plain text mode 
    Since you specified a name for your database connection, you should make sure the model connect to "LocalDB" instead of the default db.

  10. #10
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    Ok I solve it. I had a folder in my bin folder named "plugins" with the old libs. Sorry sorry for the trouble, shame on me ;o(.
    I just forget to change the lib in the folder for deploy purposes....

  11. #11
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    Another question by the way I don´t want to open new thread.
    I have only one error ore misfunction.

    When I read from mssql database a field with type decimal,
    the line:
    Qt Code:
    1. QString testdt = q.value(2).toString();
    To copy to clipboard, switch view to plain text mode 

    return an empty string. In the mssql database the field is filled with 0.24 ???

  12. #12
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Problem wit 2010.01

    Thanx, for your attention. I solve it.

    In the Docu stands :
    Constant Value Description
    QSql::LowPrecisionInt32 0x01 Force 32bit integer values. In case of floating point numbers, the fractional part is silently discarded.
    QSql::LowPrecisionInt64 0x02 Force 64bit integer values. In case of floating point numbers, the fractional part is silently discarded.
    QSql::LowPrecisionDouble 0x04 Force double values.
    QSql::HighPrecision 0 The default behavior - try to preserve maximum precision.

    High precision is declared here as default, but I must set explicitly the policy to QSql::HighPrecision.

    Curious?!

    In my Program the default precisionPolicy is QSql::LowPrecisionDouble

Similar Threads

  1. Problem with compiling Qt 4.6 via MSVC 2010 Beta2 (win32-msvc specs)
    By Erik-Moscow in forum Installation and Deployment
    Replies: 2
    Last Post: 17th December 2009, 18:44
  2. problem building 2009.3.1 with visual studio 2010 beta
    By majestik666 in forum Installation and Deployment
    Replies: 2
    Last Post: 25th September 2009, 04:13
  3. Possible to compile Qt 4.5 source with msvc 2010 beta?
    By JimDaniel in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd July 2009, 14:19

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.