Qt - How to build a standalone app with OpenCV and Qt - c++

I was able to connect Qtwith OpenCV and the my application is working properly. But now would like that my .exe file does not have any dependencies with .dll files. I would like be able to use my application in another computer without concerns.
I tried to search in several forums but i didnĀ“t find any solution to my problem.
Adding CONFIG += static to my .pro file is enough??

You need to add the CONFIG += static indeed, besides that you need to create a static build of OpenCV, Qt, and statically link it all into an exe.
I shared my setup here.
Just clone the repo and follow the instructions :)

check out bin2h. it can convert your dll file to a header file that you import into your project. you can then write out to file the generated header and then dynamically link it to your executable

Related

build c++ (qt) program as one portable file with built-in dependences

I have a Qt project. I can build it but I have to keep all external files near with the executable one if I want to use the exe-file as portable program. But a customer wants it to be an one executable without any other files. The size of result file does not matter.
So, if I would use Python, I could do it like this:
[localhost#localhost ~]$ pyinstaller --onefile myscript.py
Can I do the same using Qt (with MinGW)?
It depends on the files you are talking about. With static linking you can get rid of dll files and by using Qt resource collection files you can for example link pictures and html files into your executable.
You could package your bundle into a self-extracting ZIP that automatically runs and cleans up after itself. I found this answer that gets you close.
You can't unless you have a commercial Qt license or if you don't link to any of the Qt libraries (you could still use Qt creator and qmake).

Qt Release DLL Error

I have a project in Qt Creator and am trying to compile a static release. To do so, I have added "static" to my "CONFIG" option in my .pro file.
After rebuilding all the files, I get a folder named "release" with an executable and a few other files inside of it. When trying to execute the generated file, I get an error that reads as such:
"The procedure entry point __cxa_throw_bad_array_new_length could not be located in the dynamic link library C:\Qt\5.5\mingw492_32\bin\QtCore.dll"
This error message remains whether I use mingw 5.5.0 or 5.4.2 to compile the files.
Using dependency walker and coping the "correct" QT dll files also does not resolve the problem.
What I know already: This error happens to people who copy the wrong QTCore.dll to their project folder. However, since I am not copying any .dll files, I don't know how to use this information to my advantage.
In conclusion, my question is: How do I stop this error from occurring? Moreover, is there a better way to statically compile a qt application?
To build static release of your application you basically need two things:
1) add
CONFIG += static
in your .pro file (you did it) and don't copy any Qt dlls.
2) you need to build static Qt
https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
By default Qt is installed prepared for dynamic linking, this is why you need to build static Qt on your own.
You may want to look also at this great Q&A:
Qt static linking and deployment
but it deals mainly with Qt4. Idea is the same.
After you will build static Qt you will need to rebuild your application. And don't copy any Qt dlls.

deploying c++/qml application - packing qml files into bin

I have a c++/qml applicaiton. My/custom qml files are packed in a resource file and loading well. My problem is that when I deploy my application I need to have in bin directory also all the QtQuick/QtQuick2 directories with all their content. Is there a way to have them packed/included in compiled .exe file? In theory I could include all in a resource file, but that seems like overkill.
Is there some way how to handle this?
You can use static linking to make a standalone executable:
https://wiki.qt.io/Build_Standalone_Qt_Application_for_Windows

failed to load platform plugin "windows" Available platforms are: windows, minimal

Hi Im trying to execute my .exe file from the debug folder.
Now before you go telling me about all the other related articles Ive looked at them all and their solutions are not helping with my problem.
Ok first off Im using Qwt library and trying to create a set of gauges. I got a gauge working now I need to get it to execute from the .exe.
Ive tried adding the platforms folder in with my directory and adding the windowsd.dll and minimald.dll but still does not work.
Please advise on any course of action this had got me stumped.
Also one post says to create a qt.conf file and place it in the directory but I cant find out how to make a .conf file.
UPDATE
the error reads
debug error!
Program:
...build-Desktop_Qt_5_0_1_MSVC2010_32bit-Debug\debug\gauge.exe
Module:5.0.1
File: kernel\qguiapplication.cpp
Line:781
Failed to load platform plugin "windows". Available platforms are:
minimal
Windows
When deploying Qt on Windows, you have to copy over a number of the dlls from the bin folder of the Qt directory.
On my system it is:
C:\Qt\4.8.4\bin
After you copy over all the required dll's from there, like QtCore4.dll and QtGui4.dll, if you are using any additional plugins like phonon or jpeg support, you need to copy those dll's over from the plugins folder:
C:\Qt\4.8.4\plugins
For example I make a folder in the folder with my exe called imageformats and I put qjpeg4.dll in that folder.
As far as Qwt works, you probably need to do a similar process to expose those dll's to your exe, and put them in the same folder as your exe.
The dll's listed above are for the "release" build of your exe. If you are running the "debug" version, it will look for <dll_name>d.dll.
The reasoning for putting in those paths has to do with the library search order that windows uses.
Qt, Phonon and multimedia codecs: how to bundle them?
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx
http://qt-project.org/doc/qt-4.8/deployment-windows.html#creating-the-application-package
Hope that helps.
If you have several executable and\or you don't want to copy plugins by hand, you can create a qt.conf file with the path to the plugin directory
[Paths]
Plugins = PATH_TO_QT_DIR/plugins
You need to place the qt.conf file where the executable is.
More information at http://doc.qt.io/qt-5/qt-conf.html

Using sqlite under windows

I'm developing an app with Qt and sqlite. I had no problems while I was working under Linux, but now I have to switch to Windows for a while, and i'm stuck with a simple question.
I've downloaded the sqlite source, and compiled it with Qt as a static library. As an output, I've got three files: libsqlite.a, shell.o and sqlite3.o. I strongly believe that the libsqlite.a is my static library.
Now, I want to use it in my project. In the project directory, I've created a folder called sqlite, and put the files inside of it.
After that, I'm trying to add the library to my project. In the .pro file, I add this:
LIBS += -L"/sqlite" -l"libsqlite"
However, I keep getting an error saying:
cannot find -llibsqlite
What am I doing wrong?
"lib" prefix must be omitted.
Use the
-lsqlite
linker directive.
P.S. Another viable option is including the SQLite's sources directly to your project. There's a SQLite "amalgamation" package (only sqlite3.c and sqlite3.h files).