What database and why?
-
Hi I'm new to the forum, I was wondering what is the easiest solution for database using Qt creator 4.7 2010.05 version.
Now personally im used to use MySQL for open source solution, and in closed source well yeah companies as forced me to use
Oracle, SQL Server and sometimes even access (-.-).now I've been trying to connect to a MySQL which is stored on a server I've setup localy right next to my development machine.
what I've tryed and failed -. ( 1 year ago is to make mysql work with Qt )
but now I decided not to quit this time! :)so I'm asking all the pro do be patient with a noob like me and explain me why this isn't working out for me! ( please :o )
I've done this
@changed QT += core gui => QT += core gui sql
#include <QSqlDatabase>// ----------------------------------------------------------
void frmMain::on_BtnTableOrder_pressed()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("dpos");
db.setHostName("localhost");
db.setUserName("root");
db.setPassword("");if( db.isOpen() ) { db.close(); } else { qDebug() << QString::fromAscii("failed to connect :( reason:") << db.lastError().text(); }
}
// application output.
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
"failed to connect :( reason:" "Driver not loaded Driver not loaded" @ -
Could it be that you haven't given the correct server name for the database server you're using?
Try changing this line:
@db.setHostName("localhost");@
to use the IP address of your database server. Also I'm pretty sure MySQL requires the root account to have a password.
-
-
[quote author="Andre" date="1298273948"]It is really very simple. Your code is not at fault (at least, it is not the main issue). The error message is quite clear: your Qt MySql driver plugin is not loaded. Did you actually build it? It is not build by default when you install the SDK... [/quote]
Hi Andre, i've tryed to read a bit some places about this, and yes I do know about the missing driver thats why I posted the compile output :].
what I'm wondering is it possible to connect to mysql without having to recompile example by using
QODBC Drivers.
-
You might be able to use ODBC, but if possible, you'll want to avoid that and use the direct driver instead. ODBC is not known for its speed...
The MySQL driver by default only comes in sourcecode format, so you'll have to build it yourself. Depending on the platform you're on, that is really not so hard. You don't need to recompile all of Qt, just compile the driver.
-
[quote author="Andre" date="1298371048"]You might be able to use ODBC, but if possible, you'll want to avoid that and use the direct driver instead. ODBC is not known for its speed... The MySQL driver by default only comes in sourcecode format, so you'll have to build it yourself. Depending on the platform you're on, that is really not so hard. You don't need to recompile all of Qt, just compile the driver.[/quote]
if you have time could you please provide my the link where it explain step by step how to compile the drivers for mysql under windows and linux. ( I heard that linux you can use a sudo apt-get under unbuntu for the drivers already compiled ).
-
Perhaps "this":http://christopher.rasch-olsen.no/2009/04/14/qt-45-and-mysql-plugin-with-mingw-on-windows-xp/ will give you a head start? I have found other guides (Google is your friend!), but they are basically the same idea. Note however that you do NOT need to rebuild all of Qt, as the guide linked above suggests. Simply issue the mingw32-make command in the driver directory instead.
-
I know this is a ol post but I used this to be able to use MySQL on windows if it can help anyone.
http://ieatbinary.com/2011/07/11/how-to-enable-mysql-support-in-qt-sdk-for-windows/
-
Hi dsylebee. If you understand french, see this simple tutorial :
http://www.siteduzero.com/tutoriel-3-267200-maitrisez-les-bases-de-donnees-avec-qtsql.htmlgood luck !
-
I do understand French though the topic is not about knowing how to use queries it's how to compile the drivers of MySQL for QT, but thanks anyways.
[quote author="issam" date="1341397726"]Hi dsylebee. If you understand french, see this simple tutorial :
http://www.siteduzero.com/tutoriel-3-267200-maitrisez-les-bases-de-donnees-avec-qtsql.htmlgood luck ![/quote]