MySQL not connecting in QT application - mysql

I'm working on a database-driven QT project (basically a journal/diary tool) that will eventually allow users to connect with MySQL, SQLite, and Postgres. For now, only the MYSQL module is built, but i'm having problems making it work on Windows.
I'm compiling against a static-built QT 4.7.4 library on windows 7, and this allowed the program to find the QMYSQL driver properly. I know this because I'm not getting the "QMYSQL driver not loaded" error when I build everything staticly. However, when I try to connect to the database, I get "QSqlQuery::exec: database not open" errors. At first, I thought this was because the remote database wouldn't accept connections from my address, but I couldn't connect to localhost (as root, with the correct password) either.
I know the application code is good because it works perfectly on Linux (Same QT version, non-static build... it seemed to "just work" when built on Linux without any extra steps) so I'm wondering if QT is built correctly on Windows. I wrote a batch file to automate the build process:
TITLE Build QT 4.7.4 (static)
ECHO ON
cd C:\qt-4.7.4\
path C:\MinGW\bin
configure.exe -opensource -platform win32-g++ -release -static -qt-sql-mysql -l mysql -I C:\include -L C:\lib
PAUSE
mingw32-make
PAUSE
Am I building QT correctly on Windows? When I first experienced this problem, I followed these instructions: http://rag.com.au/linux/qt4howto.html but it still wouldn't work after the most recent build.
I had to build QT staticly because without that my application couldn't find the QMySQL driver. At first, I tried using the includes/libraries from the MySQL 5.5 community edition, but the build failed about halfway through for some reason. (It didn't like something about that particular libmysql.lib) When I tried using the headers/libs I compiled against in Linux, the build finished properly, but I'm getting this problem now.
Does it matter where the Headers/Libraries are stored when QT is compiled?
Also, I have a triple-core CPU. During Windows build, I noticed that mingw32-make only used one core since my CPU was pegged at 33% the whole time. Is there a way to make it use the whole CPU so it won't take 4-5 hours to build?
Thanks in advance for any help/suggestions.

Try this to get the available drivers for you.
QSqlDatabase * db = new QSqlDatabase;
qDebug() << db->drivers();
This will give you the list of available drivers.
Check whether "QMYSQL" is there or not.
If it is not there, you'll have to install the driver.
Check this link for the installation.

Related

Deploy Qt MySql Application

I'm working on Win10 64bit with Qt5.10.1, VS2017, MySql 8.0(64it). Everything is fine in my computer. After I deploy my application on other computers, a error message "Driver not load" pop up.
I have checked many forums including two posts in stackoverflow, [Qt][QMYSQL] Deployed app - Driver not loaded
Deploying qt mysql application
But it doesn't work for me. The following are the dll files in my folder:
qsqlmysql.dll is included in the folder sqldrivers.
All of the platform, software, SDK are 64 bit. can anyone help me? thanks.
Thanks everyone who answer my question. I tried many methods and almost give up. I never used MySQL before and this time I choose the newest MySql 8.0.12. I ignore the procedure and post the solution directly:
Beside libmysql.dll and qsqlmysql.dll, other two *.dll files are also necessary (but no solution I searched refers to them): libeay32.dll and ssleay32.dll, they are located at MySql/bin/. For my computer, they are contained in the system path, while for other computers that do not install MySql, they lack these two. Thus, we need to copy them to the package as well.
For anyone who encounter the same problem, for example using the newest MySql 8.0, you can try this method.

Can't open MySQL Utilities

Trying to open MySQL Utilities in the MySQL Workbench and get the following error:
"The command line MySQL Utilities could not be located. To use them, you must download and install the utilities package for your system from www.mysql.com. Click on the Download button to proceed."
However, when I go to the address and download/install, this does not fix the issue.
How do I fix or get around this issue?
I'm running Windows 8.1 64-bit
in error the system is not able to recognize it (MySQL Utilities could not be located) and in default assumes thats Python has been installed and the whole library are developed with Python :
The library is written entirely in Python, meaning that it is not necessary to have any other tools or libraries installed to make it work. It is currently designed to work with Python v2.6 or later and there is no support (yet) for Python v3.1.
so if you don't have Python on your system just install and its should fix the problem.

Application does not connect to database when deployed on another computer

I built a qt application that connects and queries a database using mysql . it works perfectly fine on my development computer (the computer with Qt Creator on it). but when I deploy it using windeployqt.exe and run it on another computer it doesn't connect to the database for some odd reason.
Note that I do have a working database (mysql as well) on the other computer (the one that fails to connect to the database)
I'm not sure what to do, I tried using addLibraryPaths but it didn't work (I'm not even sure if I did it correctly).
I'm using :
mysql server 5.5.36
workbench 6.0
Qt Creator 5.4.0
I also tried looking into statically building my application but I failed to understand the procedures in doing so.
I would greatly appreciate it if any of you Qt gods could help with this.
i finally found the problem and solved it.
problem: for some reason the target computer wasnt recognizing or reading libmysql.dll in C:\Windows ,and thanks to #Marco i used db.LastError and got my application to display the error , it was "Driver not Loaded Driver not Loaded" which meant that there was something wrong with libmysql.dll (note i copied this dll from MySql folder installed on the target machine )
Solution : i had to copy libmysql.dll from my development machine and place it in C:\Windows on the target machine (i noticed that libmysql.dll on my target machine was smaller in size than the one i used on my development machine)
for some reason the program only operates when the libmysql.dll from the development machine is present in C:\Windows in the target machine
this solution should fix any "Driver not loaded" or "QMySQL driver not loaded "(etc) errors . thanks everyone for trying to help , thanks again #Macro
I assume you built your application in release mode instead of debug mode.
If you have libmysql.dll and qsqlmysql.dll alongside your executable. Create a directory/folder and name it sqldrivers. Place qsqlmysql.dll in the directory you created and deploy it alongside your executable.
PS: I didn't see nnb's comment earlier. I think he's saying the same thing as my answer
From the comment we have cleared that there is a problem loading the driver, I am confident that you have the put qsqlmysql.dll in the correct place, as you have used the deploying utility, so I suspect that the problem is qsqlmysql.dll needs another dll that cannot be found in the system path.
I suggest that you run this tool:
http://www.dependencywalker.com/ on the qsqlmysql.dll
That will help you finding out what is missing, when you find that out, you will probably have to modify the system path or to install a dll that is missing.
I know this thread is old, but I've been having the same issue, and the solution was very easy (once you know).
The problem is that when you execute your application inside Qt, it will find the needed dll to load the drivers (libmysql.dll) if you located it in the correct Qt folder (Qt/path_to_compiler/bin), in my case: C:\Qt\5.9.1\msvc2017_64\bin. But when you try to execute the deployed executable, it is not able to find it. You will notice that the problem is solved if you paste the dll in C:\Windows, as #Nelioussness said. But that's not the solution, as it won't work in a different computer.
Just go to MySQL installation folder and look for the file libmysql.dll if you didn't do it before. In my case, it was located in C:\Program Files\MySQL\MySQL Server 5.7\lib. Once you find it, copy it to your release folder, exactly at the same level as the executable. It didn't work for me when I put it inside 'sqldriver' folder and everything was solved by just putting it outside, next to the .exe
Hope this helps :)

Cross compiling mySql client in DS-5 eclipse

I am trying to access an SQL server from a c/c++ application using mySql on an embedded ARM processor running Debian. I am compiling using the DS-5 eclipse based IDE (with gcc) under Windows.
The problem is that several of the header files are only present as '.h.in' files which I presume from googling is an autoconf thing. I am somewhat lost as to how to move forward.
Is autoconf something I can get eclipse to handle, or do I have to do this separately?
How is this configured for the target device rather than the compiling machine?
And as a last question, are there any lighter weight SQL clients that I should be looking at?

Problems with Qt Sql drivers

I have the following strange situation here I need some help with:
I am building a Qt application with MySQL access. For this I have:
- a dedicated building machine, using Qt 2010.05 and a MySQL 5.1 just for the libraries, Windows 7 32 bit. This machine creates the install package.
- a dedicated development machine, CentOS 5.5
- two testing machines:
- - an "always" fresh install of Windows 7
- - another Windows 7 machine with a newer Qt on it used for other stuff too.
I have built the previous version of the application sometime in February this year (on the bilding machine), it works nicely and perfectly, loads the MySQL driver (I have put it in the sqldrivers directory as indicated by everyone else). The install package installs, works everywhere (at least on all my Windows machines).
Now, I have built another release of the application, on the same machine. In the install package the only important difference is the executable (and some HTML files, but those are not relevant). Everything else is the same. When I run the NEW executable on the build machine I get ("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC") as the QSqlDatabase::drivers() output. If I run the NEW exectuable on any other machine I get an empty list of drivers. If I run the OLD package on any machine it works...
The loaded modules by the two processess (old executable, new executable) are basically the same, except is the qtmysql DLL which gets loaded in the old one and not in the new.
Have you ever encountered a situation like this? If yes do you have a feasible solution for it?
Thanks,
f.
Qt will only load plugins which are compatible with the program or version of Qt used. See the Deploying Plugins document.
You could also try using QPluginLoader to manually load a plugin and check what is reported as the QPluginLoader::errorString when it doesn't load (add the error message to your question if you can't fix it still).