Results 1 to 6 of 6

Thread: Qt and mysql on fedora 9

  1. #1
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt and mysql on fedora 9

    Hi all,

    These are the packages that i have installed:

    [cbarmpar@localhost ~]$ rpm -qa | grep qt
    qt-x11-4.3.5-2.fc9.i386
    qt3-3.3.8b-14.fc9.i386
    qt-doc-4.3.5-2.fc9.i386
    avahi-qt3-0.6.22-10.fc9.i386
    qt-sqlite-4.3.5-2.fc9.i386
    dbus-qt-0.70-4.fc9.i386
    qt-postgresql-4.3.5-2.fc9.i386
    qt-4.3.5-2.fc9.i386
    qt-devel-4.3.5-2.fc9.i386
    qt-odbc-4.3.5-2.fc9.i386
    qt3-MySQL-3.3.8b-14.fc9.i386


    i do start the mysql service with this command: /etc/init.d/mysqld start
    and i recieve the ok message.


    when i am truing to compile the following program :

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qsqldatabase.h>
    3.  
    4. int main( int argc, char *argv[] )
    5. {
    6. QApplication app( argc, argv );
    7.  
    8. QSqlDatabase *db = QSqlDatabase::addDatabase( "QMYSQL3" );
    9. db->setDatabaseName( "patent" );
    10. db->setUserName( "root" ); // change if your username is different
    11. db->setPassword( "password" ); // change if your password is different
    12. db->setHostName( "localhost" );
    13. // db->setPort( 3306 ); // dont need it in case of localhost
    14.  
    15. if ( !db->open() )
    16. {
    17. qWarning( "Failed to open database: " + db->lastError().driverText() );
    18. qWarning( db->lastError().databaseText() );
    19. printf( "Error connecting");
    20. return 1;
    21. }
    22. else
    23. {
    24. printf( "Connected " );
    25. }
    26. return 0;
    27. }
    To copy to clipboard, switch view to plain text mode 

    i recieve the following error:

    Qt Code:
    1. main.cpp:2:26: error: qsqldatabase.h: No such file or directory
    2. main.cpp: In function ‘int main(int, char**)’:
    3. main.cpp:8: error: ‘QSqlDatabase’ was not declared in this scope
    4. main.cpp:8: error: ‘db’ was not declared in this scope
    5. main.cpp:8: error: ‘QSqlDatabase’ is not a class or namespace
    6. make: *** [main.o] Error 1
    To copy to clipboard, switch view to plain text mode 

    i am using qt 4 but it appers to have the mysql qt3 driver is that a problem?

    kindest regards

  2. #2
    Join Date
    Jul 2006
    Location
    Atlanta, GA
    Posts
    86
    Thanks
    26
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and mysql on fedora 9

    It doesn't look like you have the qt4 mysql driver installed. From a cmd line, do

    yum install qt-mysql

    also check your project file that it has

    Qt += sql
    fnmblot
    --------------------------------------
    Gee Ricky, I'm sorry your mom blew up.

  3. #3
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and mysql on fedora 9

    Many thanks.

    I tried to compile it and I receive the following error:

    qmake -project && qmake && make
    g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o main.o main.cpp
    main.cpp:3:24: error: QSqlDatabase: No such file or directory
    main.cpp:4:21: error: QSqlError: No such file or directory
    main.cpp:5:21: error: QSqlQuery: No such file or directory
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:9: error: variable ‘QApplication app’ has initializer but incomplete type
    main.cpp:10: error: ‘QSqlDatabase’ was not declared in this scope
    main.cpp:10: error: ‘db’ was not declared in this scope
    main.cpp:10: error: ‘QSqlDatabase’ is not a class or namespace
    main.cpp:9: warning: unused variable ‘app’
    make: *** [main.o] Error 1
    the code that I am trying to compile is:
    Qt Code:
    1. #include <QMessageBox>
    2. #include <QSqlDatabase>
    3. #include <QSqlError>
    4. #include <QSqlQuery>
    5.  
    6. int main(int argc, char *argv[]) {
    7.  
    8. QApplication app(argc, argv);
    9. QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL");
    10. db->setDatabaseName("patent");
    11. db->setUserName("root"); // change if your username is different
    12. db->setPassword("Kalite86"); // change if your password is different
    13. db->setHostName("localhost");
    14. // db->setPort( 3306 ); // dont need it in case of localhost
    15. if (!db->open()) {
    16. qWarning("Failed to open database: " + db->lastError().driverText());
    17. qWarning(db->lastError().databaseText());
    18. printf("Error connecting");
    19. return 1;
    20. } else {
    21. printf("Connected ");
    22. }
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 

    all the modification of my pro file are being lost after i rn the qmake command.

    Many thanks in advance
    Last edited by jacek; 4th September 2008 at 19:58. Reason: changed [code] to [quote]

  4. #4
    Join Date
    Sep 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and mysql on fedora 9

    In additon: if You use qt4 headers must be <QApplication> and <QSqlDatabase>

  5. #5
    Join Date
    Aug 2008
    Posts
    52
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt and mysql on fedora 9

    i ve included the header and i still cant compile it

    cbarmpar@localhost test]$ qmake -project && qmake && make
    g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o main.o main.cpp
    main.cpp:3:24: error: QSqlDatabase: No such file or directory
    main.cpp:4:21: error: QSqlError: No such file or directory
    main.cpp:5:21: error: QSqlQuery: No such file or directory
    main.cpp: In function ‘int main(int, char**)’:
    main.cpp:11: error: ‘QSqlDatabase’ was not declared in this scope
    main.cpp:11: error: ‘db’ was not declared in this scope
    main.cpp:11: error: ‘QSqlDatabase’ is not a class or namespace
    make: *** [main.o] Error 1

    echo $QTDIR
    /usr/lib/qt-3.3

    why is that qt3 and not 4?
    Last edited by jacek; 4th September 2008 at 19:56. Reason: changed [code] to [quote]

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and mysql on fedora 9

    If you already have a .pro file, you don't have to run qmake -project anymore. Edit your .pro file and add QT += sql, then run qmake and make.

  7. The following user says thank you to jacek for this useful post:

    cbarmpar (7th September 2008)

Similar Threads

  1. MySQL currency storage problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 09:04
  2. mysql configuration with qt
    By bala in forum Installation and Deployment
    Replies: 3
    Last Post: 6th November 2007, 11:02
  3. qt4.3.1 mysql problem
    By twells55555 in forum Qt Programming
    Replies: 5
    Last Post: 8th October 2007, 21:26
  4. MySQL starting problem
    By shamik in forum General Discussion
    Replies: 5
    Last Post: 25th April 2007, 07:20
  5. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23

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.