Set QT base directory through system variable - c++

I've compiled QT and copied it over to a network drive. But now I've got the problem that the platform plugins are only found on my computer because it seems that those path got compiled into the binaries. How can I make QT to look into another directory? I thought that the system variable QTDIR should work but it gets ignored completely. Also tried to add a bunch of directories to the PATH variable which didn't work either.
I need a solution which is useable without changing the code itself.

If you need to load Qt plugins from different path you must use environment variable QT_PLUGIN_PATH.

Qt also looks for the plugins in directories relative to the path where the executable is installed. You need to properly deploy your applications, and you definitely don't need to copy the entirety of Qt anywhere. You also don't need to set QT_PLUGIN_PATH - it's a workaround for a simple problem.
Ideally, as part of your application's release build process you should be creating an installer, and that installer would then handle putting all the plugins into the application's installation folder.

Related

Running my GIS application using dev-c++ gives "gdal201.dll is missing"

I'm working on a GIS application in C++ using Dev-C++, and to start for now I'm using the code given in the tutorial in Link
I got it to compile without errors or warnings, but when I try to run it I get the error "The program can't start because gdal201.dll is missing from your computer. Try reinstalling the program to fix this problem."
I was looking at another question with the similar problem and tried to search this dll on internet, but couldn't find it anywhere, and somebody mentioned to ignore the error, but I don't know how to do that.
Can anybody help me on what to do here?
Thanks in advance.
You need the DLL file(s) to be present either in the same directory as the executable, or in your Path variable for the system to be able to find them. I personally prefer setting Path. You might consider either adding GDAL_DIR\bin to your permanent Path by editing system or user environment variables, or else create a small batch file on the desktop which adds the directory to Path then starts devenv.exe if you need to manage several incompatible development environments for different projects.
(This has several advantages in my experience over copying the DLL files to the same directory as the executable: It's easier to manage dependencies by including all the necessary directories, as opposed to manually tracking down all the recursive dependencies. It's also easier to manage updates of the DLLs if you can just update the GDAL installation directory, or update Path or the batch file to a newer GDAL installation directory, rather than having to track down all the places you've copied the DLLs to or having to manage post-build scripts to copy the DLLs every time.)
(Of course, when it comes time to create a self-contained installer, it's going to be easiest to copy the dependent DLLs to the installer image directory before building the installer. Then something like CMake's BundleUtilities module can help in tracking down what DLLs need to be included.)
Usually I copy private DLLs to the output folder of the project, i.e. the same folder as the executable. For a commercial application, you may want to install the DLL, let the OS handle the management of it and use the Assemblies Manifest to help the loader find it.

Qt platform plugin "windows" is not found on one computer

I have an application built with Qt 5.5, deployed and running on x86 Windows 7 with dynamic linking. When I try to launch it on that particular computer, I get the following error:
This application failed to start because it could not find or load the
Qt platform plugin "windows".
Available platform plugins are: minimal, offscreen, windows, windows.
Reinstalling the application may fix the problem.
The "windows" plugin is indeed repeated twice in the list.
Though I have the libraries set up properly, such that they run without an issue on my main computer, here, the platforms directory doesn't seem to be found.
File list:
MyProject\platforms\qwindows.dll
MyProject\Qt5Core.dll
MyProject\Qt5Cored.dll
MyProject\Qt5Gui.dll
MyProject\Qt5Guid.dll
MyProject\Qt5Widgets.dll
MyProject\Qt5Widgetsd.dll
MyProject\MyProject.exe
Many similar questions can be found about this error, but I have tried all the answers I have found about it (including changing file and folder names, adding various extra Qt libraries to the directory, etc.) without success. I have built the application again while making sure that all components have the right architecture, again without success.
Other than static linking, how can I make it run?
You need to put the folder 'platforms' from the \$QTDIR\$version\$complier\plugins\ (which must contains the files qwindows.dll and qminimal.dll) near your .exe file.
Usual list of dlls for Qt 5 on Windows:
Try to use windeployqt.
It'll try to autocollect all needed libraries.
Setting the QT_QPA_PLATFORM_PLUGIN_PATH environment variable worked for me.
This solution was also mentioned here and here.
Open Cmd and write this for qtquick deployment (remove --qmldir for non qtquick):
windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>
For example:
windeployqt --qmldir C:\Users\Administrator\Documents\Dyn
amicView C:\Users\Administrator\Documents\build-DynamicView-vc-Release\release
Write windeployqt for more details.

Application failed to start because it could not find or load the QT platform plugin "windows"

I have looked through all of the questions that appear to be related on stack overflow, and none of the solutions seem to help me.
I am building a Qt application with this setup:
Windows 7 Professional x64
Visual Studio 2012
Qt 5.2.0 built with configure -developer-build -debug-and-release -opensource -nomake examples -nomake tests -platform win32-msvc2012 -no-opengl
Project uses QtSingleApplication (qt-solutions)
Application is a 32 bit application
qmake run with the following: -makefile -spec win32-msvc2012
.pri uses QMAKE_CXX += /D_USING_V110_SDK71_
I can build and run my program fine on my development machine (noted above); I can also install and run the package from Program Files directory on dev machine.
When I install and run on a Windows Vista machine (multiple machines)
VC++ redist 2012 11.0.61030.0 installed
VC++ redist 2010 10.0.40219 installed
plus 2005, 2008 versions of redist
(also fails on a clean install of Windows 7)
I get:
Application failed to start because it could not find or load the QT platform plugin "windows"
So I followed the instructions and added a .platforms/ directory, and added qwindows.dll (also added qminimal.dll and qoffscreen.dll); I also added libEGL.dll, libGLESv2.dll (even though I shouldn't need them I don't think)
Once I added qoffscreen.dll I now get the additional message: Available platform plugins are: offscreen
If I run through Dependency Walker I get this error listed:
GetProcAddress(0x76CA0000 [KERNEL32.DLL], "GetCurrentPackageId") called from "MSVCR110.DLL" at address 0x6AC6FDFA and returned NULL. Error: The specified procedure could not be found (127).
and then further down get the:
GetProcAddress(0x745A0000 [UXTHEME.DLL], "BufferedPaintUnInit") called from "COMCTL32.DLL" at address 0x745FFBF8 and returned 0x745AE18C.
This application failed to start because it could not find or load the Qt platform plugin "windows".
Available platform plugins are: offscreen.
Reinstalling the application may fix this problem.
Any ideas how to fix this dll issue?
The error is caused because the program can't find qwindows.dll
qwindows.dll has to be in a folder named platforms so that the path from your executable to the dll is platforms/qwindows.dll
Whereas this wasn't enough in my case. I had also to add following line at the beginning of my main()
QCoreApplication::addLibraryPath("./");
Then everything worked.
The application is able to run on the host system, since the Qt bin path is in the system PATH variable.
There is a standard Qt tool for deployment of Qt applications on Windows windeployqt to be able to run the application on target machines that do not have Qt installed.
That tool takes care about Qt DLL dependencies, makes a copy of platforms\qwindows.dll and also it makes a copy of libraries that you cannot detect with the Dependency Walker, since image plugins and some other DLLs are loaded at runtime.
You do not even need to have your Qt bin folder in your environment PATH. The simplest deployment:
copy built exe binary to a new folder
open cmd console in that folder
call windeployqt using the full path (if it is not in the system PATH) and provide your executable, for example:
c:\Qt\Qt5.2.1\5.2.1\msvc2010_opengl\bin\windeployqt.exe application.exe
As a result you have in that folder all needed Qt DLLs to run the application.
The tool windeployqt has various options. It can also take care about deployment of qml related files.
Of course you can have also issues with MSVC redistributables, but those should be deployed separately and installed once per system.
Only some 3rd party libraries should be copied manually if they are used, for example OpenSSL.
I got this issue and how I solved it:
Used dependency walker(http://www.dependencywalker.com/) to see the exact path of the dlls needed. Try it because both QtCreator and QT framework both have the same dlls and you must pinpoint the exact ones used.
I copied all dlls needed in the same folder as the app.
I have copied the folder platforms from QT framework /plugins and copied it in the same folder as the app. Now the app comtained also plugin/platform/ folder with all its dlls
And the most important step in my case is to create a file named qt.conf in the same folder as the app . This file should contain the path to the plugins. My qt.conf file contains:
[Paths]
Libraries=../lib/qtcreator
Plugins=plugins
Imports=imports
Qml2Imports=qml
I had the same issue "Application failed to start because it could not find or load the QT platform plugin "windows"
I fixed this by copying below files to the app.exe (my app executable) folder,
Qt5Core.dll, Qt5Gui.dll, Qt5Widgets.dll and a "platforms" directory with qminimal.dll, qoffscreen.dll, qwindows.dll.
I hope this will help someone
Note this issue can also be caused if the search path for qwindows.dll that is encoded in your app includes the path where you installed Qt. Consider the following scenario:
I install Qt to c:\Qt\...
I develop an app and deploy it correctly somewhere else.
It runs on any computer properly because it includes qwindows.dll in a subdirectory.
I upgrade my local Qt to a new version.
I try to run my app again.
The result is this error, because the qwindows.dll in c:\Qt\... is found before the one in its local directory and it is incompatible with it. Very annoying.
A solution is to place a file qt.conf in the same directory as your exe file. I don't know how to avoid this. If you used the tool windeployqt.exe to deploy your app, so you have a subdirectory called platforms, then this is sufficient:
[Paths]
Plugins=.
For me, I needed to set QT_QPA_PLATFORM_PLUGIN_PATH to the platforms directory and then it worked.
For what it's worth, this solution was also mentioned on GitHub.
For the people who have this problem in the future - I have a dirty little hack, worked for me. Try at your own risk.
Follow all the steps in Initial deployment (Quick and dirty) [http://wiki.qt.io/Deploy_an_Application_on_Windows]
Close Qt Creator.
Copy the following into C:\Deployment\ The release version of MyApp.exe All the .dll files from
C:\Qt\5.2.1\mingw48_32\bin\ All the folders from
C:\Qt\5.2.1\mingw48_32\plugins\
(If you used QML) All the folders from C:\Qt\5.2.1\mingw48_32\qml\ Rename C:\Qt\ to C:\QtHidden\ (This turns your PC into a clean environment, just like one that doesn't have Qt installed).
Launch C:\Deployment\MyApp.exe.
Now for the hack -
Duplicate your folder for safety
If your file was in /cat/Deployment, go to /cat
Now, delete the Deployment folder while the .exe is still running.
It will tell you that it cannot delete certain files, so say Skip(or skip all)
What you're left with is the list of all the .dll files that your .exe was actually using and could not delete: the list of all the files and only the files that you need to keep.
You can close the .exe file now.
To check whether it is deploying okay, go into the folder where you installed it, say C:/Qt and rename it to C:/NotQt (basically make Qt invisible to the system).
If it works now, it will deploy on other systems more often than not.
Well I solved my issue, although I'm not sure what the difference is:
I copied every dll from my qt directory into both ./ and ./platforms of my application directory.
The application got past the error, but then crashed.
VERSION.dll was causing the crash (noted in dependency walker), so I removed it from both places.
The Application started up, so I systematically removed all unneeded dll's.
This got me back to the same state I had originally.
I then uninstalled my application and re-installed (with only the ./platforms/qwindows.dll file remaining), application works correctly.
So all I can assume is that I had an incorrect version of qwindows.dll in the platforms directory.
I got the same issue:
1. it can run in VS2010;
2. it can run in a folder with files as:
app.exe
\platforms\qwindows.dll
...
but it failed to load qwindows on a clean machine with same OS as the developing one.
Solved simply by move the platform folder to plugins:
app.exe
plugins\platforms\qwindows.dll
plus: qwindows.dll can be renamed as any you like as it is queried by an plugin interafce:
qt_plugin_query_metadata()
It's missing qwindows.dll, which normally should be in platforms, unless you add:
QCoreApplication::addLibraryPath("<yourpath>");
If you don't do this btw, and put your qwindows.dll somewhere else, Qt will search your PATH for the DLL, which may take a LOT of time (10s - several minutes)!
I fixed this by placing qt.conf in my application's exe folder:
[Paths]
Prefix=C:/Qt/Qt5.11.2/5.11.2/msvc2017
Where:
I have installed a custom Qt kit in C:\Qt\Qt5.11.2\5.11.2\msvc2017
qt.conf informs the app where the custom kit via the Prefix property. Note use forward slashes not backslashes (!)
And, optionally, the Qt kit's bin folder is included in my PATH environment variable
Defining Prefix in your qt.conf file allows it to find the qwindows.dll platform plugin when your app starts.
Tried all the above - turned out for me it was simply because I didn't have the main Qt dlls in the apps folder
Qt5Core.dll
Qt5Widgets.dll
etc
You need to add environmental variable QT_QPA_PLATFORM_PLUGIN_PATH to the system which points to the platforms directory in QT plugins. In my case, I was using Anaconda and PySide2. Therefore my directory path was C:\ProgramData\Anaconda3\envs\cv\Lib\site-packages\PySide2\plugins. This fixes the issue for every QT project. Otherwise, you have copy platforms directory to every QT project.

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

Qt not working correctly

I have just installed Qt_SDK_Win_offline_v1_1_4_en.exe and run QT Creator.
I am working on Win7 64 bit.
I wanted to make simply app with form and button on it to test Qt. I choose New->Project QT Widget->Aplikacja Gui QT ---> then Desktop application.
When I run Play Button - that should build and run the application I get a message: that I should check path and privileges. I can't also run the exe files as administrator manually because windows give me message that I don't have privileges. I gave full privileges in file Properties but then after run I am getting error that I don't have mingwm10.dll.
I gave full privileges in file Properties but then after run I am getting error that I don't have mingwm10.dll.
This means the library required can't be found in any of the locations Windows searches to find libraries. The usual method to get around this is by making sure the folder containing the copy of mingwm10.dll which the Qt SDK installs is in your PATH environment variable. Here is one of the many Google-able guides to settings those variables.
Ok, I found a partial solution, I could finally run the exe file.
First, something must have changed in my Windows7 because every new created folder (and files in it)had restrictions and noone could make all operations.
So, after changing properties of folder, I got message about missing dlls files, so I started to copy them from QT folder. There are at least a few different versions of each dll, and only one is correct, so I copy those form mingw folder bacause I used mingw compiler, and finally after copying 4-5 dll I run the exe file.
But this is not what I am expecting from app that install pack has almost 2GB...
thanks
m.