Error: could not find or load the Qt platform plugin “windows”
I am trying to deploy my Qt 5.3.2 application and I am getting the 'could not find or load the Qt platform plugin "windows"' error message.
I built Qt to c:\Qt\5.3.2\vs2013_64bits using Visual Studio 2013 64 bits.
QTDIR is set to c:\Qt\5.3.2\vs2013_64bits.
I am following this guide:
I have tried so far:
I renamed the directory c:\Qt\5.3.2 to c:\Qt_5.3.2_ to hide it.
I copied the whole qtbase\platforms directory to my deployment directory.
This didn't work.
I copied the directory c:\Qt\5.3.2\vs2013_64bits\qtbase\plugins\platforms to c:\Path\qtbase\plugins\platforms.
Path is a directory in my PATH environment variable.
This didn't work.
It looks as if Qt is trying to load the plugins from a hardcoded c:\Qt\5.3.2\vs2013_64bits\qtbase\plugins\platforms.
Is there any way to set this value to be relative to my application directory?
Hi and welcome to devnet,
Can you show your deployment folder current content ?
And maybe a silly question but did you build your application in release mode ?
Don't modify your PATH and don't set QTDIR. This is not needed in any way and can be harmful to your own machine setup and has no relevance on the user machine. You should not change these on the user machine.
bq. I copied the whole qtbase\platforms directory to my deployment directory.
You should not have the qtbase folder in your deployment folder, only the platforms folder and the contenst of plugins folder (no plugins folder itself either). Look at the pictures in the link you posted.
Here is a snapshot of my deployment dir:
Shouldn't the plugin folders be located in a plugins directory? Have you tried running windeployqt?
I copied the plugins directory and its contents to the deployment directory, but that didn't work.
What is the purpose of windeployqt? Should I run this on my user's machine?
When I changed the QTDIR and PATH environment variables I was expecting to get the same error messages on machine, but I am not, that's what makes me think that somehow these paths are hardcoded in my Qt dll files.
And I do have to change the QTDIR very often to switch from Qt 4.7.1 and Qt 5.3.2. (not as much now that everything is installed).
I copied the entire directory:
To my user's machine c: drive, and now I can execute my application in that machine.
This tells me that somehow the path c:\Qt\5.3.2\vs2013_64bits is coded in my application or the Qt dll files.
Is there any way to tell Qt where to look for these plugins?
Thank you again!
Hi, I had same problem as you, and decided to learn more about Qt and its plugins. Turns out there are in total 7 (!) different ways you can tell Qt where to look for the plugins, I've written about it "here":http://www.tripleboot.org/?p=536#PluginDLLs
Thank you very much hskoglund!
Your guide seems very complete... I'll study it carefully.
I also found this:
And when I look to the QLibraryInfo::PluginsPath in the debugger it is:
Which apparently is set when the library is built or using qt.conf.
Thank you again!
According to this guide:
You can set the plugin path using QCoreApplication::addLibraryPath.
I tried to assemble the plugins path using QCoreApplication::applicationDirPath(), but this method requires that an instance of QApplication has been initialized, which fails because of no plugins!
The only way I found to set the path was using argv[ 0 ] and boost:
boost::filesystem::path exe_path = boost::filesystem::system_complete( boost::filesystem::path( argv ) );
boost::filesystem::path dir_path = exe_path.parent_path();
QString plugin_path( dir_path.string().c_str() );
plugin_path = plugin_path + "/qt_plugins";
plugin_path.replace( "\", "/" );
QCoreApplication::addLibraryPath( plugin_path );
This works but the argv[ 0 ] makes it iffy.
Hi, if you just want to tell Qt to look for the plugins in a subdirectory below your .exe file, you can use a relative path syntax (i.e. no C: or slashes):
Yes, using a relative path was the first thing I tried, but it didn't work.
Hmm just tried it, maybe my testapp is too simple. Anyways, there are other alternatives to tell Qt about that path, you could try creating a qt.conf file and place it together with your .exe file, and stuff it with these 2 lines: