QMYSQL driver not loaded on Windows - c++

I am trying to implement a database system in my Qt application. For this purpose, I am trying to use MySQL (with the related QMYSQL driver). My class connection-function is written below.
Assuming that connection is defined as a private class member:
private:
QSqlDatabase connection;
we have the following:
database::database() : connection() {
this->connection.addDatabase("QMYSQL");
this->connection.setHostName(p.database->server_addr);
this->connection.setUserName(p.database->username);
this->connection.setPassword(p.database->password);
this->connection.setDatabaseName(p.database->database_name);
if (!connection.open())
this->error = this->connection.lastError().text();
else this->error = "";
}
I get database::error with the value Driver not loaded Driver not loaded (yes, it's written twice). I've seen here on Stack Overflow that I have to put the driver libraries in my application's path. I've done this and nothing happened. Below is a screenshot of the Qt libraries that are in my path.
EDIT
After calling QSqlDatabase::drivers(), I found out that I have the drivers available. Below is the output ( int the show-more section of the message-box).

For mingw and Windows: Download the C (not c++) connector from: https://dev.mysql.com/downloads/connector/c/,
then copy the library: libmysql.dll, to the folder: D:\Qt\5.5\mingw492_32\bin.
This should solve the problem for the not loaded driver.

1) I assume that you already compiled your qsqlmysql dll. You should have the qmyssql.dll in the plugins/sqldrivers directory relative to your binary path of your executable.
2) You should also be careful not to mix release and debug dlls (the ones with the d at the end).
3) The static method addDatabase should be used this way: this->connection = QSqlDatabase::addDatabase(DRIVER, NAME);
4) Another point: The reason you get the error "twice" (you actually just get two errors combined) is that connection.lastError().text() results a combined error message (appended) from the driver and from the connection attempt (see the API more more information about the differences).
5) When i took a closer look at your libs i could not see the non-debug version of libmysql.dll. If you run in release mode you must use the release library since the runtime will look for libmysql.dll and not libmysqld.dll. This will give you this error.

In addition to #OnWhenReady's answer, I run the DependencyWalker on the qsqlmysql.dll and found that there were missing some dependencies.
IEShims.dll
I copied it in my path and now it's working!
As a tip: run DependecyWalker for this kind of libraries, because, as it's written in the Qt Documentation, QMYSQL driver libraries won't give errors (won't show them).

Please see the link for QT5:
http://seppemagiels.com/blog/create-mysql-driver-qt5-windows
=> qsqlmysql.dll and libmysql.dll (and libmysql.lib, if your installation of MySQL has it) are needed
And the link for QT4:
http://seppemagiels.com/blog/create-mysql-driver-qt-windows
=> libqsqlmysql4.a and qsqlmysql4.dll and libmysql.dll (and libmysql.lib, if your installation of MySQL has it) are needed

I use msys2 with its qt5 package mingw64/mingw-w64-x86_64-qt5 (5.8.0-3) and looking at the plugins/sqldrivers/qsqlmysql.dll with the Dependency Walker reveled dependency on the mariadb.dll, so I installed the mariadb client package:
pacman -S mingw64/mingw-w64-x86_64-libmariadbclient
and the dll appeared in /mingw64/bin/mariadb.dll, so I just copied the dll next to my app's exe file and it suddenly worked.
Even if you don't use msys2, you should still look at your qsqlmysql.dll with Dependency Walker and provide the missing dlls to your app. You can install MariaDB or MySQL connectors and just copy the dlls from the installed path.

I have encountered this problem many times. If you are in
LINUX: You need to build it. You need to first install MySQL server then MySQL Client from package manager. then follow instructions in Qt Documentation website Here. Which is basically these commands:
cd $QTDIR/qtbase/src/plugins/sqldrivers/mysql
make install
and after the build process finishes, generated plugin will in $QTDIR/qtbase/src/plugins/sqldrivers/ i guess.
WINDOWS: No need to build. Install MySQL and after that you can
Install MySQL Connector C (.msi file) and add installation destination folder to PATH.
or download the zip file and extract it in somewhere that your application can find.
also, if you have done all above and still doesn't work, you need to install Visual C++ Runtime Libraries. I had this problem in XP and Dependency Walker didn't show any missing or incompatible .dll file and after installing those runtime libs my problem was solved. Where you can find them packed and ready? Here
Before you test your app, its a good idea to reboot so those changes in PATH and ... can take effect.

Related

c++ libdl.so: Can't open shared library in 32bit application

I am writing a little project in which I want to call a function from a shared library. For that I want to use libdl.so's dlopen() function.
I have everything set up so that it will work just fine when I build and run it as a 64bit application. However as soon as I am compiling it as a 32bit application and then try to run it, it won't be able to load any library.
dlopen() simply returns null and a call to dlerror() reveals
libtbbmalloc.so.2: cannot open shared object file: No such file or directory
Now I am guessing that I have to somehow install a 32bit version of that library but I can't find it in the package manager and what I have found online isn't too helpful either.
Does someone know that the problem is and/or how I could fic it?
I am building my project via cmake v3.10 and in the CMakeLists.txt I am using this instructions for 32bit:
set_target_properties(clib PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_link_libraries(clib /usr/lib32/libdl.so)
I have installed the package g++-multilib and my g++ version is 7.3.0.
I am attempting to build my program on Linux Mint 18.3 (6bit).
With the help of #Lorinczy Zsigmond in the comments, I was able to find the problem: I had to install the packages libtbb-dev:i836 and libz-dev:i836 in order for the function loading to work properly.

Building Qt static, can't find MinGW

I'm trying to build a static version of Qt, so I could make a .exe file of my project.
I have found this tutorial, and am using the script made by the tutorial author. When I try to run the script, my PowerShell gives me this>
Building static Qt version 5.3.1
ERROR: MinGW environment not found, no Qt prebuilt version?
Press Enter to continue...:
This is impossible. I know this because I already had made projects with Qt5 and built them with my MinGW compiler.
Some additional info:
MinGW is located:
C:/Qt/Tools/mingw491_32 (/bin/gcc.exe)
When I open the script, theres this line>
#Search all instances of gcc.exe from C:\Qt prebuilt environment.
$GccList = #(Get-ChildItem -Path C:\Qt\*\Tools\mingw*\bin\gcc.exe | ForEach-Object FullName | Sort-Object)
So, to me it looks like the gcc should be found by the script.
Anyone have any ideas as to what is happening here?
Thanks.
Replace
C:\Qt\*\Tools\mingw*\bin\gcc.exe
with
C:\Qt\Tools\mingw*\bin\gcc.exe
Not exactly the answer to your question but probably the solution for your problem.
There is no need to make Qt static for creating an executable of your sources. The static option is more appropriate for embedded system without OS, or with a very thin OS below. I can't imagine, it would make sense on windows.
Build a release version, copy your exe and all required dlls of Qt and mingw to one directory and copy this directory to any windows pc. It should work.
For checking, which dlls are required, use depends-tool
For providing your exe in a more professional way, create an installer. I'd recommend Inno Setup, which is very easy to use.
In case you want to copy the dlls use windeployqt, its very simple than using dependency walker. This will copy all the dlls for you to a given folder...
Copy <MyApp.exe> to a folder say <MyAppPackage>
cd to <MyAppPackage>
C:\Qt\Qt5.7.0\5.7\mingw53_32\bin\windeployqt.exe MyApp.exe
All the dlls will be copied to <MyAppPackage> folder.
It helped me:
The path that reads " C:\Qt*\Tools\mingw*\bin\gcc.exe" needed to be changed to " C:\Qt\Tools\mingw*\bin\gcc.exe" on my (Windows 10) system.
https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW

QT missing dll after deploy

I've copied all of the dlls from QT that were required, and my application works fine on my Windows server machine.
However when trying to run it on a Windows 7 box i get the following message:
This application failed to start because it could not find or load he
Qt platform plugin "windows".
Reinstallning the application may fix this problem.
Any ideas what I'm missing here?
I'd scratched my head over this some time ago. It turned out that this was caused not by missing qwindows.dll, but rather one of libEGL.dll or libGLESv2.dll. This was tricky, because dependency walker does not show those libs as direct dependencies.
If you want to test on your dev machine, whether your app has all required libs, fire up console issue SET PATH=, cd to your app directory and run it.
This is complete list of dlls that my app is using (Qt 5.2 / QtQuick app only, rest is C++). QtQuick is nice but the size of Qt dependencies is a bit scary:
icu*.dll - depending on whether you've compiled with ICU
libEGL.dll
libGLESv2.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Widgets.dll
Widely used solution is put all necessary libraris in the folder of application.
What are libraries application need?
Run application and see error message:
The program can't start because <Library name> is missing from your computer.
Try reinstalling the program to fix this problem
Library set is depended from Qt version. Run several times application and each time copy required lib you found what is neeeded for application.
In my case (Qt 5.2.1) there are
icudt51.dll,
icuin51.dll,
icuuc51.dll,
libgcc_s_dw2-1.dll,
libstdc++-6.dll,
libwinpthread-1.dll,
Qt5Core.dll,
Qt5Gui.dll,
Qt5Widgets.dll.
All libs you can found in your Qt install folder. But don't use libraries from Tools\QtCreator folder, because QtCreator has another version of these libraries!
In case of error:
This application failed to start because it could not find or load he Qt platform plugin windows. Reinstallning the application may fix this problem.
You should create folder platforms and copy qwindows.dll into it.
If you still got error you should create qt.conf file in application's folder with content:
[Paths]
Plugins=plugins
This solution is described in https://qt-project.org/forums/viewthread/37265
More information about qt.conf you can find at http://qt-project.org/doc/qt-5/qt-conf.html
In latest versions of Qt you can find deploy tool (since 5.2). This tool find necessary libraries for application and copy into application folder. You can run it something like this:
call c:\Qt\QtX.Y.Z\X.Y.Z\mingw48_32\bin\qtenv2.bat
cd /d "c:\path\to\your\application\folder"
windeployqt.exe your_application.exe
Generally it works well. But I notice that some libraries are not copied, but you can found by method is descibed at beggining of post. More useful information you can find at
http://qt-project.org/doc/qt-5/windows-deployment.html
In rare cases yo can got this error if some library is missing but not appear in error message above. Example: Qt 5.1.1: Application failed to start because platform plugin "windows" is missing
I wasn't in this situation, so I can't tell more.

lib clang.dylib: change installation path

I have a problem using libclang:
I built libclang locally. It resides somewhere like clang-llvm/…/libclang.3.4.dylib.
Then I developed a foundation tool using that dylib. (exactly: I copied a version to my project folder and linked against this.) The foundation tool works fine. But, of course, at load time it uses the dylib in my local build folder. This is unacceptable, because the user of the tool has to install clang to use my tool.
So I copied libclang.3.4.dylib to a location inside /usr/…/libclang.3.4.dylib and changed the installation path to that location using install_name_path -id /usr/…/libclang.3.4.dylib /usr/…/libclang.3.4.dylib.
After that my tool finds the dylib there but does not work since the parser cannot find stdarg.h any more in the file, that is parsed by my tool.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:12:10: fatal error: 'stdarg.h' file not found
How can I set the installation path of libclang.3.4.dylib to something public?
Amin, my good friend.
<sarcasm>
From what you wrote it should be OBVIOUS to EVERYONE that you have to create a release build of your tool and NOT a debug build. Xcode should have told you that in the form of CLEAR and EASY to understand error messages.
</sarcasm>
Solution: Use a release build of your tool instead of a debug build.
:)

How do i configure SDL to work with the Blackberry Playbook Native SDK / NDK?

I've got the NDK set up and managed to compile and run the hello native sdk project on my playbook. I downloaded the blackberry sdl port from github. However I've been unable to compile even a hello world project using it. Also it seems to be lacking a "lib" folder which I'm used to needing for the compiler settings.
EDIT: I have managed to get the sdl to open in the native sdk, it seems the download was designed to act as a project template of sorts. At first the compiler complained that i needed another library, TouchControlOverlay. So I downloaded this and set up the includes to include it. However again I couldn't find a lib folder, and the project still wont compile, saying it cannot find -lTouchControlOverlay.
The reason the compile cannot find TouchControlOverlay is because it's not installed on your host machine. To install it:
Clone TouchControlOverlay from here: https://github.com/blackberry/TouchControlOverlay
Go into the directory and run:
make && make install
If you now navigate to: $QNX_TARGET/armle-v7/lib you should see that libTouchControlOverlay.so has been placed there. You should now be able to link against this library using -lTouchControlOverlay
Note that you will need to package this library with your application by specifying it as an <asset> in your bar-descriptor.xml file.