Results 1 to 13 of 13

Thread: Connect to database

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: Connect to database

    First of all,

    you shouldn't translate database connection parameters.

    Second, why do you use QODBC driver and not QPSQL?
    A camel can go 14 days without drink,
    I can't!!!

  2. #2

    Default Re: Connect to database

    just to be sure, when you say translate you mean de tr() that I use around my char[] s, right?
    If I don`t translate it, it gives me an error saying that there is no function for char[], if I try to put it untranslated on a QString it gives me a "conversion from const char[] to QChar is ambiguous". I will try using it from a textfield but I don`t have much hope it will change anything.
    Second, 'why' you ask? boss orders, of course! XD. But now following what you said, I tried with QPSQL and got a:

    Qt Code:
    1. QSqlDatabase: QPSQL driver not loaded
    2. QSqlDatabase: available drivers: QSQLITE, QODBC3, QODBC
    3. "Driver not loaded Driver not loaded"
    To copy to clipboard, switch view to plain text mode 

    So I think I have better chances with anyone of those three....

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: Connect to database

    If you MUST use ODBC you have to configure ODBC on your system and provide the correct database name

    void QSqlDatabase::setDatabaseName ( const QString & name )
    ....
    For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.
    For example, Microsoft Access users can use the following connection string to open an .mdb file directly, instead of having to create a DSN entry in the ODBC manager:
    ...
    db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=myaccessfile.mdb");
    if (db.open()) {
    // success!
    }
    ...
    There is no default value.
    To correct configure ODBC use documentation.

    I suggest you to not use QObject::tr because if you translate your app, the connection parameters cannot be changed
    A camel can go 14 days without drink,
    I can't!!!

  4. #4

    Default Re: Connect to database

    Following you advice I had a fist fight with my boss and, after braking my arm and foot, he decided that it would cost less to try compile qt to use the postgre pluging than to pay for my medical bill.
    Now I`m trying to compile the qt adding the psql plugin.....

    (of course I`m exagerating, but thats the feeling I have everytime he glares at me XD)

  5. #5
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: Connect to database

    You have to compile only the plugin not all Qt.

    See here

    Using native drivers can improve the performance, this is why Qt suggest to use ODBC as "LAST" solution if native drivers cannot be used.
    Last edited by mcosta; 19th April 2011 at 18:35. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  6. #6

    Default Re: Connect to database

    I`m getting and odd error....
    Warning!: I`m a windows user so I`m not familiar with compiling and such in cmd prompt =p
    The error I`m getting is 'Permission Denied' when I do nmake, but I`m using the admin acc to pass the commands....

    Qt Code:
    1. C:\Qt\4.7.2\src\plugins\sqldrivers\psql>nmake
    2.  
    3. Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
    4. Copyright (C) Microsoft Corporation. All rights reserved.
    5.  
    6. "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\nmake.exe" -
    7. f Makefile.Debug
    8.  
    9. Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
    10. Copyright (C) Microsoft Corporation. All rights reserved.
    11.  
    12. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_S
    13. UPPORT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_DLL -DQT_PLUGIN -DQT_S
    14. QL_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEX
    15. T -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I'../../../../include/QtCore' -I'../../../
    16. ../include/QtSql' -I'../../../../include' -I'c:/Program' -I'Files/PostgreSQL/9.0
    17. /include' -I'../../../../include/ActiveQt' -I'debug' -I'../../../../mkspecs/win3
    18. 2-g++' -o debug/main.o main.cpp
    19. NMAKE : fatal error U1045: spawn failed : Permission denied
    20. Stop.
    21. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0
    22. \VC\bin\nmake.exe"' : return code '0x2'
    23. Stop.
    24.  
    25. C:\Qt\4.7.2\src\plugins\sqldrivers\psql>
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Default Re: Connect to database

    Are you sure you have nmake? I have also builded qpsgl recently and the solution was to use mingw32-make instead. True, the symptom was very different, but still, if works, then fine. Was the previous step (the one with qmake) succesful?
    Szilvi

  8. #8
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: Connect to database

    I see
    ../include/QtSql' -I'../../../../include' -I'c:/Program' -I'Files/PostgreSQL/9.0
    /include' -I'../../../../include/ActiveQt' -I'debug' -I'../../../../mkspecs/win3
    2-g++' -o debug/main.o main.cpp
    Notice that the path "C:/Program Files" was splitted
    Try Quoting using qmake like

    Qt Code:
    1. qmake "INCLUDEPATH+="\"C:\Program Files\PostgreSQL\9.0\include\"" "LIBS+=\"C:\Program Files\PostgreSQL\9.0\"\lib\ms\libpq.lib" psql.pro
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. Questions about connect to remote database
    By stmk in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2010, 10:02
  2. QSqlDatabase - How to connect to multiple database?
    By cutie.monkey in forum Qt Programming
    Replies: 4
    Last Post: 10th March 2010, 12:03
  3. how to connect to a microsoft access database?
    By mismael85 in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 09:25
  4. Replies: 5
    Last Post: 28th August 2006, 14:36
  5. My application can't connect to database when deploy it???
    By gtthang in forum Installation and Deployment
    Replies: 1
    Last Post: 15th February 2006, 11:01

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.