Results 1 to 7 of 7

Thread: Connecting to my database

  1. #1
    Join Date
    Oct 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Connecting to my database

    my problem right now is that i cant connect my database to my program, im using qdevelop and mysql. this is the code that i use:
    QString HST = "localhost";
    QString USR = "root";
    QString PWD = "";
    QString DBASE = "rdmssql";
    QString DRIVE = "QMYSQL";

    QSqlDatabase defaultDB = QSqlDatabase::addDatabase(DRIVE);
    defaultDB.setDatabaseName(DBASE);
    defaultDB.setUserName(USR);
    defaultDB.setPassword(PWD);
    defaultDB.setHostName(HST);
    defaultDB.open();

    and i revceive errors like these:
    >>build\main.o(.text+0x1a1):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase17defaultConnectionE'
    >>build\main.o(.text+0x1ea):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11addDatabaseERK7QStringS2 _'
    >>build\main.o(.text+0x244):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase15setDatabaseNameERK7QStri ng'
    >>build\main.o(.text+0x268):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setUserNameERK7QString'
    >>build\main.o(.text+0x281):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setPasswordERK7QString'
    >>build\main.o(.text+0x29a):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase11setHostNameERK7QString'
    >>build\main.o(.text+0x2a9):main.cpp: undefined reference to `_imp___ZN12QSqlDatabase4openEv'
    >>build\main.o(.text+0x2f0):main.cpp: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'
    >>build\main.o(.text+0x4b5):main.cpp: undefined reference to `_imp___ZN12QSqlDatabaseD1Ev'

    please tell me what im doing wrong?

  2. #2
    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: Connecting to my database

    You need to add "QT+=sql" line to your .pro file and rerun qmake.

  3. #3
    Join Date
    Oct 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connecting to my database

    where should i place QT+=sql???

  4. #4
    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: Connecting to my database

    In your project file - the one that has a .pro extension

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Connecting to my database

    just copy the line wysota gave you and paste it in your projects pro file.

    EDIT: OOpsss... sorry, should have refreshed my browser.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Oct 2007
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connecting to my database

    thanx... it's ok now...

  7. #7
    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: Connecting to my database

    If you use Visual Studio integration, you'll need to right click your project entry in solution explorer, choose "Add Qt module" and check "SQL library".

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. connecting QT3 with MS Access database
    By raghvendramisra in forum Qt Programming
    Replies: 1
    Last Post: 2nd February 2007, 09:48
  3. updating database
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 05:54
  4. submitAll() : database error
    By locus in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2007, 05:49
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

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.