Solved QCoreApplication::setLibraryPaths from CMake
-
I can set LibraryPath from C++. How I can set LibraryPath from CMake by passing a variable?
I work on Windows. There is no QT installed on a machine where I deploy. I provide all libs, but I do not want them to be in the same folder as .exe. -
This is not possible - how should this work at all?
https://forum.qt.io/topic/104721/windows-minimum-files-in-deployment-that-cannot-be-moved
-
CMake:
set(QT_PLUGIN_PATH "C:/Program Files/qtPluginsFolder") add_definitions( -DQT_PLUGIN_PATH=\"${QT_PLUGIN_PATH}\")
C++:
QStringList pluginsPaths; pluginsPaths << QT_PLUGIN_PATH; // QT_PLUGIN_PATH set in cmake. QCoreApplication::setLibraryPaths(pluginsPaths);
-
@christof said in QCoreApplication::setLibraryPaths from CMake:
CMake:
set(QT_PLUGIN_PATH "C:/Program Files/qtPluginsFolder") add_definitions( -DQT_PLUGIN_PATH=\"${QT_PLUGIN_PATH}\")
C++:
QStringList pluginsPaths; pluginsPaths << QT_PLUGIN_PATH; // QT_PLUGIN_PATH set in cmake. QCoreApplication::setLibraryPaths(pluginsPaths);
This sets the environment variable on the development PC, but the environment variable cannot be transferred to deployment PCs. -
@jksh said in QCoreApplication::setLibraryPaths from CMake:
Do you mean the cmake part? If I understand correctly, add_definitions does not set the environment variable, but
Adds definitions to the compiler command line... what allows us to add preprocessor definitions. -
Hi,
Out of curiosity, why do you want to add that path ?
Do you have any special requirements ? -
@christof said in QCoreApplication::setLibraryPaths from CMake:
@jksh said in QCoreApplication::setLibraryPaths from CMake:
Do you mean the cmake part? If I understand correctly, add_definitions does not set the environment variable, but
Adds definitions to the compiler command line... what allows us to add preprocessor definitions.You're right; sorry for the noise!
I'd still recommend picking a different name for the preprocessor definition, to make it clear that it's not the QT_PLUGIN_PATH environment variable that Qt expects.
-
-
Is that folder relative to the executable file ?
-
The folder location may change in future therefore I do not want to provide a relative path.
-
The problem you will get with using absolute paths is that your users may very well not install your application in the same disk, nor the same folder that you hardcoded.
-
Another solution is to set the environment variable during the software installation. Using Wix:
<CPackWiXPatch> <CPackWiXFragment Id="CM_DP_lib"> <Component Id="EnvQml2ImportPath" Guid="****"> <CreateFolder /> <Environment Action="set" Id="Qml2ImportPathEnv" Name="QML2_IMPORT_PATH" Part="last" Permanent="no" Separator=";" System="yes" Value="[INSTALL_ROOT]qt"/> </Component> </CPackWiXFragment> <CPackWiXFragment Id="#PRODUCTFEATURE"> <ComponentRef Id="EnvQml2ImportPath" /> </CPackWiXFragment> </CPackWiXPatch>
Then, use this enviroment variable in the cpp:
QStringList pluginsPaths; pluginsPaths << std::getenv("QML2_IMPORT_PATH"); QCoreApplication::setLibraryPaths(pluginsPaths);