[SOLVED] First Steps and MySQL
-
Hello.
I'm just getting started with Qt on Linux and windows8.1 but I stalled with drivers for MySQL.
In both installations (Linux and Windows), I used the package for offline installation :- Qt 5.4.0 for Windows 64-bit (VS 2013, OpenGL, 709 MB)
- Qt 5.4.0 for Linux 64-bit (542 MB)
On windows to compile I'm using VisualStudio 2013 Express.
In both cases I able to compile and run the sample programs and my small programs.
Now I need to figure out how to establish a connection to a MySQL DataBase.
I tried to compile the sample program sqlbrowser but when I try to connect to MySQL I get this error on both operating systems:@Starting/home/francesco/Qt5.4.0/Examples/Qt-5.4/sql/build-sqlbrowser-Desktop_Qt_5_4_0_GCC_64bit-Debug/sqlbrowser...
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
/home/francesco/Qt5.4.0/Examples/Qt-5.4/sql/build-sqlbrowser-Desktop_Qt_5_4_0_GCC_64bit-Debug/sqlbrowser exited with code 0@Now I need to know what I have to download and how compile to use MySql.
I read around a bit and now I only have a mess .In both installations of Qt there are no sources of Qt.
There is a good Samaritan that makes me a shopping list or tell me where to find the instructions for the version of Qt that I am using for Windows and Linux (Linux Mint 7.1 Ubuntu lts) ?
Thank you in advance and wish you all a great new year:-D
-
You shouldn't need to download anything else. You do have 'QMYSQL' on the list of available drivers so the plugin is there and visible.
This is what I have used in the past. I haven't tried it in 5.4.0 yet but I did try it in 5.3.2 and it worked.
Note: I use the name of the database as the connection name and the first 'if' is to see if it was used previously.
@ if(QSqlDatabase::contains(d_StartupOptions->OdbcDatabaseName))
{
Database = QSqlDatabase::database(d_StartupOptions->OdbcDatabaseName);
}
else
{
Database = QSqlDatabase::addDatabase(d_StartupOptions->OdbcDatabaseDriver,d_StartupOptions->OdbcDatabaseName);
}Database.setDatabaseName(d_StartupOptions->OdbcDatabaseName);
Database.setUserName(d_StartupOptions->OdbcUserName);
Database.setHostName(d_StartupOptions->OdbcHostName);
Database.setPassword(d_StartupOptions->OdbcPassword);
Database.setPort(d_StartupOptions->OdbcPortNumber.toInt());if(Database.open())
{
...
}@
Have you tried to login to the database (using a terminal window) on either (or both) windows and linux to verify it is setup properly and working?
-
No. I know the variable names suggest ODBC but I am not using this anymore (too many issues across operating systems).
You can shorten down the add database command to this:
@
Database = QSqlDatabase::addDatabase("QMYSQL");
@The connection name would be 'defaultConnection' if not specified.
-
Hi and welcome to devnet,
Two things comes to mind:
Do you have the MySQL client libraries installed on your system ?
If yes, do you have the path to the folder containing the dlls in the PATH environment variable ?
If no, you can update the content of that PATH in Qt Creator Run part of the Project panel.
Hope it helps
-
[quote author="SGaist" date="1419980992"]Hi and welcome to devnet,
Two things comes to mind:
Do you have the MySQL client libraries installed on your system ?
If yes, do you have the path to the folder containing the dlls in the PATH environment variable ?
If no, you can update the content of that PATH in Qt Creator Run part of the Project panel.
Hope it helps[/quote]
Hi SGaist , thanks for the welcome and happy new year to you
On linux mint 17.1 I installed the package of client libraries but there is a version problem.
On Windows I installed the package MySQL Connectors, and then I tried to copy the dll in the directory where I compiled the sample application, but I think it is not the correct way.
What do I have to download from the website of MySQL for windows?
-
Happy new year to you too !
Run ldd on the Qt MySQL plugin to see what libraries it links to. I'd guess that you have something like plugin linked to version 16 of the client library and you have version 18 installed
-
[quote author="SGaist" date="1420068353"]Happy new year to you too !
Run ldd on the Qt MySQL plugin to see what libraries it links to. I'd guess that you have something like plugin linked to version 16 of the client library and you have version 18 installed[/quote]
Hello.
I hope you happily started the new year.I'm using a Linux mint 17.1 and for the moment I want to solve the problem here, then go on to Windows.
The version I have on my system is this: ibmysqlclient_r.so.18
In fact with ldd is specified that I need 16.@
francesco@francesco-M51AC ~/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers $ ldd libqsqlmysql.so
linux-vdso.so.1 => (0x00007fff3fdfe000)
libmysqlclient_r.so.16 => not found
libQt5Sql.so.5 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libQt5Sql.so.5 (0x00007fd3e387b000)
libQt5Core.so.5 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libQt5Core.so.5 (0x00007fd3e313f000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd3e2e3b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd3e2a75000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd3e2856000)
libicui18n.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicui18n.so.53 (0x00007fd3e240a000)
libicuuc.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicuuc.so.53 (0x00007fd3e207f000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd3e1e7a000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fd3e1c78000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd3e1a70000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fd3e1767000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd3e1461000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd3e124b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd3e3cf0000)
libicudata.so.53 => /home/francesco/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers/./../../lib/libicudata.so.53 (0x00007fd3dfbc2000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fd3df984000)@
Because I think the cleanest way to solve it is to recompile the plugin I
downloaded the source: qt-everywhere-opensource-src-5.4.0.tar.gz
And now my home is organized as below@
francesco@francesco-M51AC ~ $ tree -L 1
.
├── Documenti
├── Dropbox
├── Immagini
├── Modelli
├── Musica
├── ProgettiQT
├── Pubblici
├── Qt5.4.0
├── qt-everywhere-opensource-src-5.4.0
├── qt-everywhere-opensource-src-5.4.0.tar.gz
├── Scaricati
├── Scrivania
└── Video
@The plugin should I build is here: ~ / qt-everywhere-opensource-src-5.4.0 / qtbase / src / plugins / sqldrivers
@
mysql/
├── main.cpp
├── mysql.json
├── mysql.pro
└── README
@SGaist you can help me to compile it ?
I know we are boring and we always ask the same things but I promise that I will do an article on my blog in Italian language and in English so maybe there will be less people asking about it. :-D -
Heureka
I managed to solve
I go in to the folder containing the source code of the plugin: @~ / qt-everywhere-opensource-src-5.4.0 / qtbase / src / plugins / sqldrivers / mysql@From this folder I launched qmake (not system qmake):
@/home/francesco/Qt5.4.0/5.4/gcc_64/bin/./qmake@Then I ran a:
@make
make install@I had previously removed the original plugin: libqsqlmysql.so (save it somewhere , you never know)
Now the new plugin works (Linux mint 17.1) and I can use the demo program sqlbrowser establishing a connection to a MySQL database
And this is my new plugin dated 01/01/2015 (I hope this is a good omen for a Happy 2015):-D
@francesco@francesco-M51AC ~/Qt5.4.0/5.4/gcc_64/plugins/sqldrivers $ ls -l
total 964
-rwxr-xr-x 1 francesco francesco 797480 dic 8 22:21 libqsqlite.so
-rwxr-xr-x 1 francesco francesco 73328 gen 1 14:20 libqsqlmysql.so
-rw-r--r-- 1 francesco francesco 27381 gen 1 14:20 libqsqlmysql.so.tar.gz
-rwxr-xr-x 1 francesco francesco 85808 dic 8 22:21 libqsqlpsql.so@ -
You shouldn't need to move anything around… Where did you move the plugin folder ?
-
Sorry I was not clear in the explanation.
I have not moved the folder of the plugin but I just saved the original library to another folder in the case the new did not work.I also managed to solve the problem on Windows.
Simply I used the library for 32-bit architecture, but my application was compiled for 64-bit architecture.
The library that I had to use was in the folder: C: \ Program Files \ MySQL \ lib
Now everything works on both operating systems: Windows 7, Linux mint 17.1
I will try also with Windows 8.1On windows ldd does not exist then for the analysis I used: http://www.dependencywalker.com/
If you don't see mistakes in what I did I'll mark the post as solved.
Thanks to all
-
Nop, everything looks correct you can update the thread title :)
Happy coding !