Results 1 to 7 of 7

Thread: DB problem

  1. #1
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default DB problem

    Hi,

    I'm trying to connect to my database whit the following code:

    Qt Code:
    1. #include <QSqlDatabase>
    2. ...
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    4. db.setHostName("myhost");
    5. db.setDatabaseName("mydb");
    6. db.setUserName("myuser");
    7. db.setPassword("mypass");
    8. db.open();
    To copy to clipboard, switch view to plain text mode 

    but I'm getting this error:

    main.cpp:5:24: QSqlDatabase: No such file or directory
    main.cpp: In function `int qMain(int, char**)':
    main.cpp:17: error: `QSqlDatabase' undeclared (first use this function)
    main.cpp:17: error: (Each undeclared identifier is reported only once for each function it appears in.)
    main.cpp:17: error: expected `;' before "db"
    main.cpp:18: error: `db' undeclared (first use this function)
    mingw32-make[1]: *** [debug\main.o] Error 1

  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: DB problem

    Add QT+=sql to your project file and rerun qmake.

  3. The following user says thank you to wysota for this useful post:

    eu.x (28th February 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: DB problem

    And how exactly I do that?
    I must just add this command in the project file?

  5. #4
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: DB problem

    Yep, it worked...

  6. #5
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: DB problem

    I'm getting "Driver not loaded" error now.
    I ready this article http://doc.trolltech.com/4.2/sql-dri...gin-on-windows but i can't compile the plugin. Someone have a tutorial to compile MySQL plug-in?

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: DB problem

    Try the one in Qt Centre wiki: Building the QMYSQL plugin on Windows using MinGW
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    eu.x (28th February 2007)

  9. #7
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up Re: DB problem

    Thank you jpn!

    I was reading this article

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 13:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 13:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 15:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 22:36
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.