Results 1 to 9 of 9

Thread: Problem in using QODBC driver with qt 4.1.3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Problem in using QODBC driver with qt 4.1.3

    Hello all .. i'm a new one to qt
    i needed to connect qt with a database system
    so i used the following code

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QtSql>
    3. #include <QDebug>
    4.  
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9.  
    10. QString serverName = "LOCALHOST\\SQLEXPRESS";
    11. QString dbName = "test";
    12. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    13. db.setConnectOptions();
    14. QString dsn = QString("DRIVER={SQL Server Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(serverName).arg(dbName);
    15. db.setDatabaseName(dsn);
    16.  
    17.  
    18. if(db.open())
    19. {
    20. qDebug()<<"Opened!";
    21. }
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

    with following in .pro file

    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2012-01-14T12:52:43
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core
    8. QT += sql
    9. QT -= gui
    10.  
    11. TARGET = DB
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14.  
    15. TEMPLATE = app
    16.  
    17.  
    18. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    i've passed thorught many articles and threads and unfortunately no result
    some of them suggested to add sqldriver folder in my application directory it didn't work
    and some of them suggested to compile the odcb driver library but i faced a compliation problem (by both GUI & command line)

    any solutions please ...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem in using QODBC driver with qt 4.1.3

    Quote Originally Posted by MohdRash View Post
    any solutions please ...
    And your question is???

    First is the QODBC driver listed when you call QSqlDatabase::drivers()? And what is QSqlDatabase::lastError() telling you? Please do the basic debugging yourself next time and provide these information in your question. Our crystal balls got stolen lately...

  3. #3
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in using QODBC driver with qt 4.1.3

    quite sorry .. i have forgetten to submit the error message
    QSqlDatabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem in using QODBC driver with qt 4.1.3

    Well then it is obviously: You have to build the driver first. Because without a driver you can't use it...

    Have you tried the instructions from the documentation: http://developer.qt.nokia.com/doc/qt...ver.html#qodbc? What errors do you get exactly?

  5. #5
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in using QODBC driver with qt 4.1.3

    hello Lykurg

    i have tried
    Qt Code:
    1. cd %QTDIR%\src\plugins\sqldrivers\odbc
    2. qmake odbc.pro
    3. nmake
    To copy to clipboard, switch view to plain text mode 

    and when i apply
    qmake odbc.pro
    Qt Code:
    1. WARNING: Failure to find: ..\..\..\sql\drivers\odbc\qsql_odbc.cpp
    2. WARNING: Failure to find: ..\..\..\sql\drivers\odbc\qsql_odbc.h
    3. WARNING: Failure to find: ..\..\..\sql\drivers\odbc\qsql_odbc.cpp
    4. WARNING: Failure to find: ..\..\..\sql\drivers\odbc\qsql_odbc.h
    To copy to clipboard, switch view to plain text mode 
    however i checked the directory C:\Qt\4.1.3\src\sql\drivers\odbc

    and i found both required files exists


    an important point is that i found odbc.pro in C:\Qt\4.1.3\src\qt3support\plugins\sqldrivers\odbc
    not in C:\Qt\4.1.3\src\plugins\sqldrivers\odbc as expected

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Problem in using QODBC driver with qt 4.1.3

    what does
    bash Code:
    1. echo %QTDIR%
    To copy to clipboard, switch view to plain text mode 
    return?

  7. #7
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default Re: Problem in using QODBC driver with qt 4.1.3

    hi, im having the same problem except that i recieve the message :

    ("QSQLITE", "QODBC3", "QODBC")
    Driver not loaded Driver not loaded

    when i execute :
    Qt Code:
    1. qDebug() << QSqlDatabase::drivers();
    2. db.addDatabase("QODBC");
    3. db.setDatabaseName("GestionVinoteca");
    4. db.setUserName("admin");
    5. db.setPassword("fapfap");
    6. db.setPort(1521);
    7. bool ok = db.open ();
    8. if (ok)
    9. qDebug("OK.");
    10. else
    11. qDebug("%s", qPrintable(db.lastError().text()));
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Oct 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem in using QODBC driver with qt 4.1.3

    Back after a little journey

    here is the output

    C:\Users\MohdRash>echo %QTDIR%
    C:\Qt\4.1.3

  9. #9
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    33
    Thanked 10 Times in 10 Posts

    Default Re: Problem in using QODBC driver with qt 4.1.3

    i solved my problem, check out my solution...actually i was trying to use OCI driver for Oracle but i think it s the same...

    http://www.qtcentre.org/threads/4696...ht=#post212132

    hope it helps!

Similar Threads

  1. QODBC driver
    By hamidarr in forum Qt Programming
    Replies: 3
    Last Post: 21st July 2011, 00:09
  2. QSqlDatabase: QODBC driver not loaded
    By sattu in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2011, 11:40
  3. QSqlDatabase: QODBC driver not loaded
    By gutiory in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2010, 09:24
  4. QODBC driver
    By martisho in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2010, 19:48
  5. QODBC Driver
    By mchara in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2008, 14:40

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.