Qt Cannot open file 'sqlite3.lib' - c++

I downloaded official Database for SQLite project from GitHub. I tried to compile this project but I received an error: "Cannot open file 'sqlite3.lib'".
I'm using Qt 5.6.0.
Compile output:
LINK : fatal error LNK1104: cannot open file 'sqlite3.lib'
jom: C:\Users\loddy\Desktop\sqDebug\src\Makefile.Debug [debug\sqlitebrowser.exe] Error 1104
jom: C:\Users\loddy\Desktop\sqDebug\src\Makefile [debug] Error 2
jom: C:\Users\loddy\Desktop\sqDebug\Makefile [sub-src-make_first] Error 2
20:11:18: The process "C:\Qt\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project sqlitebrowser (kit: Desktop Qt 5.6.0 MSVC2015 64bit)
When executing step "Make"
Also, there are sqlite3.c and sqlite3.h files in project.
What should I do for solve this problem?

Qt has the ability to access SQLite databases. You could write code like this:
#include <QtCore/QCoreApplication>
#include <QtSql>
#include <qDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (!db.open()) {
qDebug() << db.lastError();
qFatal("failed to connect database.");
}
qDebug() << "database connected";
QString sql = QString("insert into tb_test values('John', 10)");
qDebug() << "sql: " << sql;
QSqlQuery query(sql, db); // query will be automatically executed if sql is not an empty string, see Qt document for details
return a.exec();
}
In above code, I asume that the database test.db has one table called tb_test. And it has two fields, name, which is varchar, and age, which is int.
Please make sure that you have Sql module loaded in your project.
FYI, Online Qt Documentation, or you could search by class names in Qt Assistant, which is installed by Qt on your computer.

Related

Qt plugin not loaded

I have problems loading the built-in plugins for iconengines for a deployed application. Below is a minimal program to show the problem. It is not exactly the same, because Qt scans the plugin directories at start and registers it according to the file suffix, but I hope when I can get the minimal program to run, then the automatic scanning works, too.
main.cpp:
#include <QCoreApplication>
#include <QPluginLoader>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QPluginLoader loader("C:/Qt/5.15.1/msvc2019_64/plugins/iconengines/qsvgicon.dll");
if (loader.load()) {
qDebug() << "load ok";
} else {
qDebug() << "load failed";
}
return a.exec();
}
and PluginTest.pro:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += main.cpp
When I start it from the Qt Creator IDE, version 4.13.1, with Visual Studio 2019, 64 bit compiled, it prints "load ok". Now I do this from a "x64 Native Tools Command Prompt for VS 2019" command prompt in the project directory:
set PATH=%PATH%;C:\Qt\5.15.1\msvc2019_64\bin
mkdir deploy
copy release\PluginTest.exe deploy
windeployqt --release release\PluginTest.exe --plugindir deploy\QtPlugins
When I start PluginText.exe from the command prompt in the deploy directory, I get the output "load failed".
Additional information: when I set set qt_debug_plugins=1 and start the real application, I see these errors:
QFactoryLoader::QFactoryLoader() checking directory path "C:/projects/deploy/QtPlugins/iconengines" ...
QFactoryLoader::QFactoryLoader() looking at "C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll"
"Failed to extract plugin meta data from 'C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll'"
not a plugin
The qsvgicon.dll file is identical to "c:\Qt\5.15.1\msvc2019_64\plugins\iconengines\qsvgicon.dll".
I found the problem. It used some other Qt DLLs from the path when starting the application. This fixed it:
xcopy /y c:\Qt\5.15.1\msvc2019_64\bin\*.dll deploy

Qt cannot load MySql driver on XAMPP

I have written a very simple test to see how database connection works. This is my first attempt :
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("testqt");
db.setUserName("aaaaaa");
db.setPassword(".bbbbbb!,");
if (db.open())
{
qDebug() << "Connected!";
}else
{
qDebug() << "Failed to connect!";
}
Why I always get this error?
Note that I have this :
I have also seen online that someone puts the libmysql.dll and I've done that but still nothing. I have installed the C and C++ mysql connector from internet. Any idea?
My SQL database is on a XAMPP server and this is the username :
Also note this:
There is mariadb but it asks for libmysql!
If you have using of MinGW compiler, download c connector from bellow link :
https://dev.mysql.com/downloads/connector/c/
Then copy "libmysql.dll" dll file to your qt path where installed :
C:\Qt\5.5\mingw492_32\bin

C++ build error in Netbeans using MinGW and Qt

I have installed the MinGW compiler and I am attempting to run a C++ QT Application from within Netbeans.
As you can see from this screenshot, I have successfully set up the native build tools using Netbeans:
Unfortunately when attempting to run my program, I get the following error:
make.exe": /bin/sh: Command not found
make.exe": /bin/sh: Command not found
make.exe": *** [.validate-impl] Error 127
BUILD FAILED (exit value 2, total time: 303ms)
Just to be clear, I am not running a complicated program, in fact, I am just trying to execute a basic generated main file:
#include <QApplication>
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
You can download my Makefile-Debug and Makefile-impl here: http://wikisend.com/download/467700/makefiles.zip
I would be extremely grateful for your help.

Connecting Qt 5.4 With MySQL on Mac - QMYSQL Driver Not Loaded

I've seen other people with this issue, but I can't find a solution that has worked. I've had MySQL downloaded for a while, and use it for web development, but this is my first time trying to hook it up with Qt.
This is my main.cpp file:
#include "mainwindow.h"
#include "passwords.h"
#include "signup.h"
#include <QApplication>
#include <QWidget>
#include <QtSql>
#include <QDebug>
#include "qsqldriver.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString servername = "LOCALHOST//QMYSQL";
QString dbname = "test";
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setConnectOptions();
QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername) .arg(dbname);
db.setDatabaseName(dsn);
if(db.open()){
qDebug() << "Opened";
db.close();
}
else{
qDebug() << "Error =" << db.lastError().text();
qDebug ( ) << QSqlDatabase :: drivers ( );
}
MainWindow w;
w.show();
return a.exec();
}
I've included the following in my .pro file:
INCLUDEPATH += /Users/tomeldridge/downloads/mysql-5.6.17-osx10.7-x86_64/include
INCLUDEPATH += /Users/tomeldridge/downloads/mysql-5.6.17-osx10.7-x86_64/lib
INCLUDEPATH += /Applications/XAMPP/xamppfiles/htdocs/xampp/sqlite/include
INCLUDEPATH += /Applications/XAMPP/xamppfiles/htdocs/xampp/sqlite
I get the error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
If I use SQLite, I get the error:
Error: out of memory opening database
I have tried building the driver from scratch using the code from the Qt documentation:
-no-sql-<driver> ... Disable SQL <driver> entirely.
-qt-sql-<driver> ... Enable a SQL <driver> in the Qt Library, by default
none are turned on.
-plugin-sql-<driver> Enable SQL <driver> as a plugin to be linked to
at run time.
Possible values for <driver>:
[ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]
This apparently requires you to have downloaded the Qt Source Code, which I went and did, so you can use Qt Configure. Something went wrong along the way, and the commands I tried to use in terminal didn't work.
I also tried moving copies of the MySQL lib files into the Qt lib directory, since I saw someone who that worked for, but I didn't have any luck.
I've done several things to try and get this to work, and I've hooked up MySQL before, but I've wasted two days trying to get a database running, so any help would be awesome.

qt connect to oracle database on windows

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;