I have an app, that should connect to database.
Under linux i've no problems, but under windows - > i've to add to system "Path" place, where QT enviroment is placed (C:/QT/Tools/QTCreator/bin) otherwise it doesn't work and shows errors like below.
id doesn't work if i place exe file on pendrive too
i would like to send this app to my firends, who shouldn't install QT environment and just run this app.
dirs on my pendrive
/
app.exe
plugins (dir)
-qsqlpsql.dll
-sqldrivers (dir)
--qsqlpsql.dll
what should i do? where did i mistake?
pro file:
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = NZP
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32{
LIBS += -L"C:/Program Files/psqlODBC/0903/bin"
}
RC_FILE += Info.rc
in my main.cpp:
QApplication a(argc, argv);
qDebug()<<QCoreApplication::applicationDirPath();
a.addLibraryPath(QCoreApplication::applicationDirPath());
a.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins");
qDebug()<<a.libraryPaths();
MainWindow w;
w.show();
return a.exec();
if i run this app under windows, where i installed QT - everythink is correct, but if i move it on pendrive or run under machine without QT framework - i become error:
QSqlDatabase: QPSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC QPSQL QPSQL7
Failed to open database connection. Invalid driver specfied.
i have looked in internet, but by now without sensible solution
help!
Ugh! i found the problem!
1.
you have in your install destination this folder structure:
yourap.exe
-plugins -> folder
--sqldrivers -> folder
and you have to copy from migws/bin not QT/Tools/Creator/bin!
---qsqlpsql.dll
in your app directory you have to copy
libeay32.dll
with you found in:
C:\Program Files\psqlODBC\0903\bin (http://www.postgresql.org/ftp/odbc/versions/msi/ - ii used https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_03_0300.zip)
in your app (main.cpp), just add path:
QApplication a(argc, argv);
a.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins/");
a.addLibraryPath(QCoreApplication::applicationDirPath());
Related
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
I'm trying to develop a QT C++ application that uses QGIS API and I can't manage Qt Creator to compile the code. I've read several topicts at gis.stackexchange and from other sources. The information is mostly outdated and I havent't found a solution. What I need is an overall guideline about the compatibility of the following items that help me find the right combination:
Qt version: tried 4.8.6 and 5.9.
Qt compiler: tried MinGW, VS2008 Express (Qt 4.8.6) and VS Community 2017 (Qt 5.9)
QGIS version: tried 2.14 to 2.18.
QGIS compile: I only use the regular OSGeo4w installer and AFAIK QGIS is compiled with Qt4 and MSVC. I've tried to compile QGIS from source using MinGW with no success (again, versions compatibility issues).
Windows version: I'm using Windows 10 64bit.
OSGeo4W or OSGeo4W64.
Qt works Ok in every case with it's own libraries, but when I try to import QGIS libraries it gives an 'undefined reference' error when building, even though intellisense works fine as it recognizes QgsApplication as a member of qgsapplication.h.
The following is just a test I can't get working. My Pro file is:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QgisWindow
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# QGIS
INCLUDEPATH += "C:/OSGeo4W64/apps/qgis-rel-dev/include"
INCLUDEPATH += "C:/OSGeo4W64/include"
LIBS += -L"C:/OSGeo4W64/apps/qgis-rel-dev/lib" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=
DEFINES+=GUI_EXPORT=
# QGIS
main.cpp is:
#include <QApplication>
#include <qgsapplication.h>
int main(int argc, char *argv[])
{
QgsApplication app(argc, argv, true);
QgsApplication::setPrefixPath("C:/OSGeo4W64/apps/qgis-dev", true);
int retval = app.exec();
QgsApplication::exitQgis();
return retval;
}
Then it fails to build/compile whith this error:
main.cpp:20: error: undefined reference to `QgsApplication::QgsApplication(int&, char**, bool, QString const&, QString const&)'
I'm actually porting a PyQgis app I've made two years ago and as I'm fairly new to Qt Creator I'm stuck at he beginning.
I found the right combination of the above mentioned items to make it possible for Qt to import Qgis libraries and build the app:
Qt 4.8.6 for MSVC2010
Qt Creator 4.3.0 (from a Qt 5.9.0 installation). Qt Creator 3.0 may be used as well.
Visual C++ express 2010 - Include Windows Kits/SDK in install
OSGeo4W - Installed qgis-ltr-dev and all libraries
Cmake 2.8.2
To launch Qt Creator I use this .bat:
Creator.bat:
ECHO Setting up QGIS DEV ENV
set PYTHONPATH=
set OSGEO4W_ROOT=C:\OSGeo4W
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
#set QMAKESPEC=win32-msvc2010
#set PATH=%OSGEO4W_ROOT%\bin;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\bin;%PATH%
#set INCLUDE=%INCLUDE%;%OSGEO4W_ROOT%\include;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\include
#set LIB=%LIB%;%OSGEO4W_ROOT%\lib;%OSGEO4W_ROOT%\apps\qgis-ltr-dev\lib
path %OSGEO4W_ROOT%\bin;%SYSTEMROOT%\System32;%SYSTEMROOT%;%SYSTEMROOT%\System32\wbem;C:\Program Files (x86)\Git\bin;C:\Tools\QtCreator\bin;%PATH%
set VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
start "Qt Creator" /B C:\Qt\Qt5.9.0\Tools\QtCreator\bin\qtcreator.exe %*
The PRO file:
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 1_hello_world_qgis_style
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
## QGIS
INCLUDEPATH += "C:/OSGeo4W/include"
INCLUDEPATH += "C:/OSGeo4W/apps/qgis-ltr-dev/include"
LIBS += -L"C:/OSGeo4W/apps/qgis-ltr-dev/lib" -lqgis_core -lqgis_gui
DEFINES+=CORE_EXPORT=
DEFINES+=GUI_EXPORT=
## QGIS
main.cpp file (adapted from Tim Sutton's examples)
// Qt Includes
#include <QApplication>
// QGIS Includes
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrendererv2.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
int main(int argc, char ** argv)
{
// Start the Application
QgsApplication app(argc, argv, true);
app.setPrefixPath("D:/GIS");
QString myPluginsDir = "<path to Qgis plugins dir>";
QString myLayerPath1 = "<path to shapefile 1>";
QString myLayerBaseName1 = "Layer1";
QString myLayerPath2 = "<path to shapefile 2>";
QString myLayerBaseName2 = "Layer2";
QString myProviderName = "ogr";
// Instantiate Provider Registry
QgsProviderRegistry::instance(myPluginsDir);
// create maplayer instances
QgsVectorLayer * mypLayer1 = new QgsVectorLayer(myLayerPath1, myLayerBaseName1, myProviderName);
QgsVectorLayer * mypLayer2 = new QgsVectorLayer(myLayerPath2, myLayerBaseName2, myProviderName);
QgsSingleSymbolRendererV2 *mypRenderer1 = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(mypLayer1->geometryType()));
QgsSingleSymbolRendererV2 *mypRenderer2 = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(mypLayer2->geometryType()));
QList <QgsMapCanvasLayer> myLayerSet;
mypLayer1->setRendererV2(mypRenderer1);
mypLayer2->setRendererV2(mypRenderer2);
// Add Vector Layers to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer1, true);
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer2, true);
// Add Layers to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer1, true));
myLayerSet.append(QgsMapCanvasLayer(mypLayer2, true));
// Create the Map Canvas
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setExtent(QgsRectangle(-63.50, -28.10, -58.33, -24.00)); // Chaco
mypMapCanvas->setWheelAction(QgsMapCanvas::WheelAction(2) , 1.2);
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
// Set the Map Canvas Layer Set
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->setWindowTitle("GIS DSH");
mypMapCanvas->refresh();
// Start the Application Event Loop
int retval = app.exec();
app.exitQgis();
return retval;
}
Paths are hardcoded (bad programming practice) but is just for this test.
And now it runs OK. Please, see my post on gis.stackexchange.com for the links and the screencaps of Qt Creator Build & Run configurations.
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.
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 am trying to decode a .wav file using QAudioDecoder class. Even though I had included the QtMultimedia module into my .pro file by adding
QT += multimedia I am receiving an error that service for the QAudioDecoder was not found. I am not able to see where to problem lies.
I am using Qt 5.1.0 with MingGW 4.8 32 bit on Windows 7.
Error message:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiodecode"
.pro file:
QT += core
QT += multimedia
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main file:
#include <QCoreApplication>
#include <QAudioDecoder>
#include <QAudioBuffer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString pathToFile = "C:/Users/Mateusz/Documents/Szkola/Sound Processing/Lab1/artificial/easy/506Hz.wav";
QAudioDecoder decoder;
decoder.setSourceFilename(pathToFile);
decoder.start();
while(decoder.bufferAvailable()) {
QAudioBuffer buffer = decoder.read();
qDebug() << "Buffer size: " << buffer.byteCount();
}
return a.exec();
}
The Multimedia module uses plugins that are different on each platform (or compiler).
See http://qt-project.org/wiki/Qt_Multimedia_Backends
On Windows you have DirectShow and MediaFoundation (WMF).
Only the WMF plugin implements audio decoding features.
WMF plugin is only available with MSVC compiler.
See http://qt-project.org/doc/qt-5.1/qtmultimedia/platform-notes-windows.html
I had the same problem in Qt5.5 running under Linux.
The problem disappeared after upgrade to Qt5.5.1 using their MaintenanceTool.
I also struggled with this issue and finally got it to work by using the MS visual studio compiler in QT Creator, like Fernando Pelliccioni suggested.
Steps were:
-Use the Qt MaintenanceTool to add support for msvc2013
-Install Visual Studio 2013
-In Qt Creator go to Projects->Manage Kits and add msvc2013
-Build and run. Now QAudioDecoder works.