PDA

View Full Version : Qt and mysql on fedora 9



cbarmpar
4th September 2008, 16:25
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 :


#include <qapplication.h>
#include <qsqldatabase.h>

int main( int argc, char *argv[] )
{
QApplication app( argc, argv );

QSqlDatabase *db = QSqlDatabase::addDatabase( "QMYSQL3" );
db->setDatabaseName( "patent" );
db->setUserName( "root" ); // change if your username is different
db->setPassword( "password" ); // change if your password is different
db->setHostName( "localhost" );
// db->setPort( 3306 ); // dont need it in case of localhost

if ( !db->open() )
{
qWarning( "Failed to open database: " + db->lastError().driverText() );
qWarning( db->lastError().databaseText() );
printf( "Error connecting");
return 1;
}
else
{
printf( "Connected " );
}
return 0;
}

i recieve the following error:


main.cpp:2:26: error: qsqldatabase.h: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:8: error: ‘QSqlDatabase’ was not declared in this scope
main.cpp:8: error: ‘db’ was not declared in this scope
main.cpp:8: error: ‘QSqlDatabase’ is not a class or namespace
make: *** [main.o] Error 1

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

kindest regards

fnmblot
4th September 2008, 17:06
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

cbarmpar
4th September 2008, 17:37
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:

#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>

int main(int argc, char *argv[]) {

QApplication app(argc, argv);
QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL");
db->setDatabaseName("patent");
db->setUserName("root"); // change if your username is different
db->setPassword("Kalite86"); // change if your password is different
db->setHostName("localhost");
// db->setPort( 3306 ); // dont need it in case of localhost
if (!db->open()) {
qWarning("Failed to open database: " + db->lastError().driverText());
qWarning(db->lastError().databaseText());
printf("Error connecting");
return 1;
} else {
printf("Connected ");
}
return 0;
}

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

Many thanks in advance

mikolaj
4th September 2008, 17:41
In additon: if You use qt4 headers must be <QApplication> and <QSqlDatabase>

cbarmpar
4th September 2008, 18:18
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?

jacek
4th September 2008, 20:57
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.