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
Re: Qt and mysql on fedora 9
Many thanks.
I tried to compile it and I receive the following error:
Quote:
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:
Code:
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
int main(int argc, char *argv[]) {
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
Re: Qt and mysql on fedora 9
In additon: if You use qt4 headers must be <QApplication> and <QSqlDatabase>
Re: Qt and mysql on fedora 9
i ve included the header and i still cant compile it
Quote:
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?
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.