So I'm try to build the MySQL plugin for qt 5.7 on Windows. I managed to generate the qmysqld.dll an qmysql.dll by doing the following
1) Downloading Qt source files
2) Navagating to QTDIR\qtbase\src\plugins\sqldrivers and running qmake on the qsqldriver.pro file while linking both mySql\include and mySql\libmysql.lib. Specifically I ran the following command:
qmake "INCLUDE+=mysql-5.7.17-win32\include" "LIBS+=C:\mysql-5.7.17-win32\lib\libmysql.lib" -o MakeFile mysql.pro
3) Running mingw32-make to compile the project.
4)I then moved both qmysqld.dll and qmysql.dll from QTDIR\plugins\sqldrivers to ACTUALQTINSTALLATION\mingw53_32\plugins\sqldrivers
The files were already there and needed to be replaced.
This is the test code I'm trying to run.
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "my_sql_db");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("");
if(!db.open())
qDebug() << db.lastError().text();
Which produces the following error, as it did before I built the plugins.
"Driver not loaded Driver not loaded"
Driver: ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
The only thing I can think of is that I ran the DependencyWalker program on qsqlmysqld.dll and it's saying that LIBMYSQL.dll, QT5CORED.dll and QT5SQLD.dll are missing and that pretty much every other dependency is for an x64 bit architecture(As opposed to qsqlmysql.dll which is 32). I know very little about what that means and it's my first time using DependencyWalker but would this indicate that I've somehow built the dll to be 32 bit and need to recompile it as a 64 bit and that should solve the issue?
Very confused about this, I've been trying to get this to work on and off for over a month now.
Related
I am attempting within my code to connect to an SQLite database:
bool MainWindow::connOpen(){
mydb=QSqlDatabase::addDatabase("QSQLITE");
//qDebug ( ) << QSqlDatabase::drivers();
QString dbpath = "dbname.sqlite";
mydb.setDatabaseName(dbpath);
}
which gives me the Error Message: "QSqlDatabase: QSQLITE driver not loaded"
as well as an error window "Driver not Loaded Driver not Loaded". The QSqlDatabase mydb declaration is in the MainWindow header file.
Strangely, this only happens in Debug Mode, in Release Mode everything ist fine. Even weirder, this used to work before (I think) an automatic QT Update. I am using QTCreator 4.4.1 and QT 5.9.2. Also, I checked, the sqlite.dll is within the sqldrivers folders, where I understand it should be. But for some reason the Qt Folder is called QT 5.9.1 unlike my actual version, only this does not seem to have any effect. Everything else works fine.
Also, when I uncomment the QSqlDatabase::drivers(); line, the output in Debug Mode is (), while in Release Mode I get ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7"). Clearly, the drivers are not being found.
Does anybody have an idea where the difference betweeen debug and release could come from? Thanks a lot!
To summarize as an answer:
The fact that release builds work, but debug fails is because on windows there are actually 2 files per plugin - in this case qsqlite.dll and qsqlited.dll. The one with the d is used for debug builds, and the other one for release builds.
As the debug variant is missing, a reinstallation of Qt is the only way to get back the missing files.
In my case:
So does not work:
db = QSqlDatabase::addDatabase("QSQLITE", "MyConnection"); //MyConnection as connection name - Driver not loaded
and it works:
db = QSqlDatabase::addDatabase("QSQLITE");
Both versions work in Release.
QT 5.10
As the title says, I've been having this issue for some days now. My program runs fine in debug mode on QtCreator, but once I choose release mode, I get the sql driver not loaded issue (I've only been running it on windows 10). I believe my .pro file is correctly written (QT += sql is written).
I've tried most things I could :
windeployqt.exe .
move plugins myself in sqldrivers sub-folder in executable folder containing all sqldrivers provided by Qt installation path and also moved at executable folder Qt5Sql.dll
I also tried using sqlite3.dll provided by sqlite website and moving it in both (one by one tested) executable folder and sqldrivers sub-folder.
As I said the issue happens only at deployement so I am wondering if there is something I should have added to my .pro file.
I don't have any sql program installed on my windows OS. If that is the issue, which I think is, I was wondering how I could force my program to use plugins provided in sqldrivers sub-folder.
Errors :
QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
QSqlQuery::exec: database not open
EDIT : I managed to fix that. The issue came from something I didn't expect. I was using global variables and one of them was my database, I realized it by reading again the error as it seemed the database was loaded before the first lines of main.cpp (at #include). So right now I'm using opening and closing the database each time I use it. Is there some way I could declare a global database (keep it open all the time) ? I'm using it quite intensively.
Yes, you can open your database once and then just use static public methods of the QSqlDatabase class:
QSqlDatabase my_db = QSqlDatabase::addDatabase("QSQLITE");
my_db.setDatabaseName("my_db_name.sqlite");
if(my_db.open())
{
my_db.exec("create table person (id int primary key, "
"firstname varchar(20), lastname varchar(20))");
}
else
{
qDebug() << my_db.lastError().text();
}
And then in another place:
QSqlDatabase db = QSqlDatabase::database();
if(db.isOpen())
{
qDebug() << "Wow";
db.exec("insert into person values(101, 'Danny', 'Young')");
}
See QSqlDatabase::addDatabase(), and use the parameter connectionName if necessary.
On Windows 7 I installed qt creator and now I am trying to connect to the oracle database. I installed oracle client and plsql/developer and everything works fine. In qt creator I have error:
QsqlDatabase: QOCI driver not loaded
This qt documentation does not work for me. Is it clear tutorial how to do it on different platforms and situations?
Ok. I found solution.
Documentation says
set INCLUDE=%INCLUDE%;c:\oracle\oci\include
set LIB=%LIB%;c:\oracle\oci\lib\msvc
cd %QTDIR%\src\plugins\sqldrivers\oci
qmake oci.pro
nmake
If you are not using a Microsoft compiler, replace nmake with make in
the line above.
but make or nmake didn't work for me. Because I have not installed Microsoft Visual c++ on my machine.
I made instruction how to do this:
At first don't forget to install qt sources. During the installation check Sources checkbox.
then download and install oracle client win32_11gR2_client.zip. choose Runtime option during installation.(even if you are using 64 bit os download 32 bit version on oracle client). It creates c:\app\user\product\client_1... directory
then open qt minGW command line(start ->all peograms -> qt[version] -> [version] -> MinGW [version] -> Qt [version] for Desktop MinGW [version]) and move to the oci source folder:
cd C:\Qt\Qt[version]\[version]\Src\qtbase\src\plugins\sqldrivers\oci
then as documentation says include OCI(Oracle call interface) path and library:
set INCLUDE=%INCLUDE%;c:\app\user\product[version]\client_1\oci\include
set LIB=%LIB%;c:\app\user\product[version]\client_1\oci\lib\msvc
5.compile oci driver by executing these two lines:
qmake oci.pro
mingw32-make
it will creates two .dll files for you qsqloci.dll(release version) and qsqlocid.dll(debug version)
last step is to copy these two files into qtcreator installation folder.
go to the:
C:\Qt\Qt[version]\[version]\Src\qtbase\plugins\sqldrivers
and copy these files into:
C:\Qt\Qt[version]\[version]\mingw[version]\plugins\sqldrivers
and you are ready to go. to check connection try this code:
#include <QCoreApplication>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setHostName("MY_IP_OR_HOST_NAME");
db.setDatabaseName("XE");
db.setUserName("test");
db.setPassword("test_password");
if (!db.open())
{
qDebug() << db.lastError().text();
}
else{
qDebug() << "Wow opened";
}
return a.exec();
}
You should use QODBC instea of QOCI.
gogagubi's answer is good, but step 4 does not work for me because set INCLUDE and LIB does not work for mingw32-make.
It need to set INCPATH and LIBS in oci.pro or use:
qmake "INCPAH +=c:\app\user\product[version]\client_1\oci\include
LIBS +=-Lc:\app\user\product[version]\client_1\oci\lib\msvc" oci.pro
Add the following lines to the oci.pro:
INCPATH +=c:\app\user\product[version]\client_1\oci\include
LIBS+=-Lc:\app\user\product[version]\client_1\oci\lib\msvc
ciao tutto;
you can connect to oracle db with QODBC driver if it exist;(default in Qt windows is exist) Like below:
QSqlDatabase db=QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
db.setDatabaseName("Driver={Microsoft ODBC for Oracle};Server=127.0.0.1:1521;Uid=ep;Pwd=605605");
if(!db.open())
exit(0);
QSqlQuery query(db);
query.exec("select * from t");
while(query.next())
QMessageBox::information(0,"",query.value(1).toString());
this is connected and allow to execurte query;
buona fortuna;
I compiled bitoin-qt,PTS coin and other Altercoins successfully ,but thay all can't running.
I use MinGW4.4 ,QT 4.8.5 download from website and QT creator 2.8.1.
This is my .pro setting:
BOOST_LIB_SUFFIX=-mgw44-mt-s-1_53
BOOST_INCLUDE_PATH=D:/C/coin/namecoinq/libs/boost_1_53_0
BOOST_LIB_PATH=D:/C/coin/namecoinq/libs/boost_1_53_0/stage/lib
BDB_INCLUDE_PATH=D:/C/coin/namecoinq/libs/db-4.8.30.NC/build_unix
BDB_LIB_PATH=D:/C/coin/namecoinq/libs/db-4.8.30.NC/build_unix
OPENSSL_INCLUDE_PATH=D:/C/coin/namecoinq/libs/openssl-1.0.1e/include
OPENSSL_LIB_PATH=D:/C/coin/namecoinq/libs/openssl-1.0.1e
MINIUPNPC_INCLUDE_PATH=D:/C/coin/namecoinq/libs
MINIUPNPC_LIB_PATH=D:/C/coin/namecoinq/libs/miniupnpc-1.8
And I uncommented this code because MinGW4.4 doesn't suport it(I've used MinGW 4.6,4.7,4.8,but they all even compiled failed) :
#win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat
These all compiled by MinGW4.4 succefully,but the debug and release exe compiled both can't run.I have coped the qt dlls to the exe direction.When I debugged it,it broke before entering the main source.
======================UPDATE edit==========================
I know it's because of leveldb,but I don't know what's wrong with my compiling leveldb:
TARGET_OS=NATIVE_WINDOWS mingw32-make libleveldb.a libmemenv.a
When I use another altercoin leveldb source code,the error solves.But I use back to the original leveldb source code,the program breaks again.
Still seems to me you are missing a .dll. Try using dependency walker and verify you are not missing any dependencies.
I am using Qt 4.8.1, MinGW compiler and Qt Creator, all on windows 7. I want to add an encryption/ decryption library to my project. After searching the web for couple days I found QCA. Fortunately I found a pre-built version using the same C++ compiler I am using, and a pre-built version of the needed plugins.
I followed the instructions to add the QCA library to my project. I used a code like this to encrypt using AES:
QCA::Initializer init = QCA::Initializer();
//Here where the execution stops
QCA::SymmetricKey key = QCA::SymmetricKey(16);
QCA::InitializationVector iv = QCA::InitializationVector(16);
QCA::Cipher cipher = QCA::Cipher(QString("aes128"), QCA::Cipher::CBC,
QCA::Cipher::DefaultPadding, QCA::Encode,
key, iv);
if (!QCA::isSupported("aes128-cbc-pkcs7"))
{
qDebug() << "AES128 is not supported";
return;
}
The code compiles just fine but when I run the application stops with unknown reason.
I really got tired from this bug, if anybody can help it will be very very very appreciated.
For future programmers that might get stuck on this
QCA loads the plugins at runtime, so even if it compiles fine, if the plugin is not in a searchable folder, it won't load.
You can check if that's the problem by calling qDebug() << QCA::supportedFeatures();. If the plugins are not being loaded, you'll get something like:
("random", "md5", "sha1", "keystorelist")
You should be able to see the folders QCA is looking up by calling:
qDebug("%s", QCA::pluginDiagnosticText().toUtf8().constData());
Apparently, plugins must be placed in a subdirectory called crypto in the libs root directory.
You can check for all the paths where Qt looks for libraries using:
qDebug() << QCoreApplication::instance()->libraryPaths();
This documentation might have some useful information: http://doc.qt.io/qt-4.8/qpluginloader.html