basic qt with mysql?
Page |
1 |
hi
i install qt creator then mysql driver for qt and then i install xampp to make databases for qt. Now i want to access data in database using qt. i am following this link but it is not working for me. Your text to link here… [doc.trolltech.com]
then problem is when i type the same code
- #include <QApplication>
- #include <QSqlDatabase>
- int main( int argc, char *argv[] )
- {
- if ( ! defaultDB ) {
- qWarning( "Failed to connect to the database driver" );
- return 1;
- }
- defaultDB->setDatabaseName( "testTwo" );
- defaultDB->setUserName( "root" );
- defaultDB->setPassword( "" );
- defaultDB->setHostName( "localhost" );
- if ( defaultDB->open() ) {
- // Database successfully opened; we can now issue SQL commands.
- }
- return 0;
- }
then it returns these errors
- defaultDB was not declare in this scope main.cpp 9
- QMYSQL was not declare in this scope main.cpp 9
how can i access data from my database table?
other thing is i am using xampp for creating mysql databases. when i make database it is placed in this directory opt/lampp/var/mysql/testTwo.
16 replies
in .pro file you should add
- QT += sql
That’s because you assign QSqlDatabase *defaultDB ( a pointer) with what addDatabase [doc.qt.nokia.com] returns (a QSqlDatabase, not a pointer to QSqlDatabase)
You can use isValid() [doc.qt.nokia.com]
now it is saying
- QSqlDatabase: QMysql driver is not loaded
i have installed Mysql driver here Your text to link here… [developer.qt.nokia.com]
well i checked this in this path home/qtsdk-2010.05/qt/src/plugins/sqldrivers
I have two plugins folders. one in home/qtsdk-2010.05/qt/plugins
in this plugin folder i have 11 folders with one named sqldrivers. inside this sqldriver folder i have these 3 files “libqsqlite.so, libqsqlite2.so, libqsqlpsql.so”
the other is mentioned above which inside src.
You must log in to post a reply. Not a member yet? Register here!




