Qt database drivers - c++

I built qt with -plugin-sql-mysql -plugin-sql-sqlite flags. I have libqsqlmysql.a and libqsqlite.a. I use qt in my project. But my build system is not qt, I use waf.
I have the following problem when I try to run my application which establishes connection with mysql database:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers:
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
INFO - Failed to connect to root mysql admin
I added -lqsqlmysql to compiler options when I build the app.
Can you please explain how qt drivers work, how and when it tries to load driver. What is a qt driver (dll, lib, ....)?

I think your app is trying to load the database plugin dynamically, from a DLL. This document will help you find the appropriate location for the database driver DLL. Alternatively, you could link your app against the plugin statically, here's how.

Qt has plugins for several types of databases and these plugins are located in the following location:
$(QTDIR)/plugins/sqldrivers
First check if mysql plugin is present there. If plugin is not there then it means you didn't compile Qt properly, so you should recompile Qt with enabled MySql plugin. Otherwise probably your application doesn't load mysql plugin properly. Qt plugins are loaded dynamically during initialization of application i.e when QSqlDatabase object will be initialized. If plugin location is not set properly then none of plugins will be loaded. You can check location where your application expect to find plugins via following Qt API:
QStringList QCoreApplication::libraryPaths ()
If application doesn't point to right location you can set plugin path by calling of:
void QCoreApplication::addLibraryPath ( const QString & path )
 
Or by creation of qt.conf file in folder where your executable is placed. In this file you can configure plugins location in the following way:
[Paths]
Plugins = %pluginlocation%

Related

Application failed to start because it could not find or load the Qt platform plugin "xcb" in

I am using Qtcreator to build and run my program. Build is success but while running I am getting the following error
This application failed to start because it could not find or load the Qt platform plugin "xcb"
Reinstalling the application may fix this problem.
I am using Qt5.6.1-1 and creator 4.0.3 based on Qt 5.6.1
Tried by exporting path
export QT_PLUGIN_PATH=/home/SysUser/Development/Qt5.6.1-1/plugins/platforms
Still its not working
I am having Qt5.12.6 also installed but this app need Qt 5.6.1 so I renamed Qt5.12.6 folder.
Any lights will be a great help

Qt release application don't see plugin

I have a problem with release application, it is don't see psql driver if i start it by exe from explorer.
But it works perfect if i start it from visual studio...
I place these files near exe, and no result:
unins000.dat
msvcp140.dll
qsqlpsql.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5Sql.dll
vccorlib140.dll
Server.exe
unins000.exe
config.json
error:
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC ODBC3 QPSQL QPSQL7
but i compiled that plugin defore!
Whats can be wrong?
To deploy qt application with plugins you should also add plugins in same folder as application. How to deploy qt applications with plugins
You should also add platform folder near application to be able to deploy your application on computers where qt isn't available.
It's on Linux but same applies in windows. You can only add sqldrivers in plugins folder.
qt.conf file contaians:
[Paths]
Plugins=plugins
Also run Dependency Walker to find all dependent libraries.

Connecting Qt5 and Firebird 2.5

I'm a newbie at c++ linking and databases, so may be i'm asking a really stupid question. Anyway, i'm trying to access to firebird database using Qt5 for Windows. I've checked google and found 2 ways of doing so:
build ibase driver from Qt source;
use firebird through ODBC driver.
Software versions
I'm using latest version of Qt: 5.1.1. Firebird 2.5 is working ok: i've create a test_base and test user admin. Administartion of test_base i've done through FlameRobin.
Building
I've downloaded qt5.1.1 source and unpacked it in c:/devtools/qt5.1.1-src. Since Qt4.7-4.8 folder and project structure has been changed so old FAQs cannot be applied here. So i tried to build sql.pro from qtbase\src\sql folder with 2 lines added:
INCLUDEPATH+= C:/devtools/firebird/firebird_2_5/include
LIBS+= C:/devtools/firebird/firebird_2_5/lib/fbclient_ms.lib
And i've added C:/devtools/firebird/firebird_2_5/lib/ and C:/devtools/firebird/firebird_2_5/include in system PATH. Compilation is done without any error and i get a qt_pch.h.gch\c++ file in build dir. And i have no idea what's to do next, because i hoped to have bunch of .a and .dll files or bunch of error at least.
Using ODBC driver
I've downloaded and installed firebird ODBC driver from here. Installation was successful and i created ODBC DSN source mydb in Windows ODBC manager. Test connection button from ODBC configurator says that everything is ok.
Next thing i did was opening SQL Browser example from Qt Creator. And it fails to open my ODBC base with following parameters:
Driver: QODBC
Database Name: mydb
Username: admin
Password: admin
Hostname: localhost
Port: Default
And i get an error message: "[ODBC Firebird Driver] Unable to connect to data source: library 'C:\devtools\Firebird\Firebird_2_5\bin\fbclient.dll' failed to load QODBC3: Unable to connect".
I'm looking for resolving any of this two issues. Thanks in advance.
upd: i've connected firebird database through ODBC: the error was in using x64 database with x86 QODBC. Nota bene: in order to manage x86 DSN ODBC in x64 Windows 7 one must run ODBC manager from %WINDIR%\SysWOW64\odbcad32.exe NOT from Administration Panel as it explained here.
But what about building ibase from qt source?

Can't deploy Qt application with QMYSQL

I have an application that requires to connect to MySQL database, I am using Qt 4.7. I built the QMYSQL plugin and everything works just fine ON MY MACHINE. When I tried to test the application on another machine with the folder "sqldrivers" contains the "qsqlmysql4.dll" next to my executable. I get this error "Driver not loaded". After hours of searching the web and following the Qt documentation I came up with nothing.
Please tell me what am I missing.
Is there an actual mysql client DLL (like libmysqlclient.dll or something) that's installed on your machine, and also needs to be included with the app?

Windows, Mingw Qt Application Does Not Run On Deployed Computers

I have created a Qt application with Mingw. The application runs properly on the development computer after copying the required DLL's to the directory. However, when deploying on external computers, the application does not run at all.
Update:
In addition, the application uses Sqlite3 via QtSql.
It's quite likely you're still missing some dll.
Check the Windows event log for any errors after running the application. (Administrative Tools->Event Viewer).
Try launching the application from a command prompt window.
Try Dependency Walker.
Another thought is some missing configuration file or registry settings.
Double check against the Qt docs for deploying Windows Qt applications.