简体   繁体   English

Qt QCoreApplication addLibraryPath使用

[英]Qt QCoreApplication addLibraryPath use

I've been having troubles with the QCoreApplication::addLibraryPath(QString &Path) method on windows. 我在Windows上遇到了QCoreApplication :: addLibraryPath(QString&Path)方法的麻烦。

I've trying to use it to add directories where the application should be looking for dll that i'm loading dynamically with QLibrary. 我试图用它来添加应用程序应该寻找dll的目录,我正在用QLibrary动态加载。

I soon enough realized that it was not the right way to go. 我很快意识到这不是正确的方法。 I now use a putenv approach to change directly my environement variables. 我现在使用putenv方法直接改变我的环境变量。

Plus, I still don't understand what exactly the addLibraryPath method is supposed to be used for? 另外,我仍然不明白addLibraryPath方法应该用于什么?

I think qt documentation is not clear enough, regarding this topic. 关于这个话题,我认为qt文档不够清晰。 There are (at least) 2 sorts of libs/dlls: 有(至少)2种lib / dll:

  • Essential Libs/Dlls das are already needed at program start (like Qt5core.dll). 程序启动时已经需要Essential Libs / Dlls das(如Qt5core.dll)。
  • "Functionality Libs" like the Qt Plugins and third party stuff, that can be loaded later. “功能库”就像Qt插件和第三方的东西,可以在以后加载。

It is not obvious (at least for me) which DLL is of sort 1 or sort 2. This leads to the problem that it may be nasty to find out which you can move into subfolders and point your application to it by addLibraryPath(). 至少(至少对我而言)哪个DLL是排序1或排序2这一点并不明显。这导致了一个问题,即找出哪些可以移动到子文件夹并通过addLibraryPath()将应用程序指向它可能是令人讨厌的。

For me the following solution worked: 对我来说,以下解决方案有效:

  • use windeploy to find out the bigger part of dependencies (my app's executable is in a "bin" folder below the project folder) 使用windeploy查找依赖项的大部分(我的应用程序的可执行文件位于项目文件夹下的“bin”文件夹中)

    • c:\\Qt\\Qt5.3.2\\5.3\\mingw482_32\\bin\\windeployqt.exe ..\\bin\\myapp.exe --release --force --compiler-runtime -libdir ..\\bin -dir ..\\bin\\plugins
    • this puts the "sort 1" libs into the app folder 这将“排序1”库放入app文件夹中
    • and the "sort 2" libs into a subfolder plugins 和“排序2”库成为子文件夹插件
  • Additionally, it is needed to let the installer set an environment var "QT_PLUGIN_PATH" in registry to let the app find the plugins. 此外,需要让安装程序在注册表中设置环境var“QT_PLUGIN_PATH”以让应用程序找到插件。 I wasted hours just to find out that setting this path with addLibraryPath() at runtime is just not working. 我浪费了几个小时才发现在运行时使用addLibraryPath()设置这条路径是行不通的。 Also a qt.conf file seems not to work. 另外一个qt.conf文件似乎不起作用。 The only alternative for me is setting a environment var in a .bat file, what is essentially the same like the registry setting. 对我来说唯一的选择是在.bat文件中设置环境变量,这与注册表设置基本相同。 Here's the registry key (in inno setup syntax): 这是注册表项(在inno设置语法中):

    Root: HKLM; 根:HKLM; Subkey: "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"; 子项:“SYSTEM \\ CurrentControlSet \\ Control \\ Session Manager \\ Environment”; ValueType: string; ValueType:string; ValueName: "QT_PLUGIN_PATH"; ValueName:“QT_PLUGIN_PATH”; ValueData: "lib" ValueData:“lib”

Another anoying thing is, that some libs are not identified by windeploy. 另一个令人讨厌的事情是,某些libs不是由windeploy识别的。 These are mainly the compiler redistributables, that will vary with the compiler that you use. 这些主要是编译器可再发行组件,它们将随您使用的编译器而变化。 Others are more depending on the functions that you use, and somehow are not processed by windeploy. 其他更多取决于您使用的功能,并且windeploy不会以某种方式处理。 This fact is not documented obviously (at least I didn't see it) and is also not easy to understand. 这个事实没有明显的记录(至少我没有看到它),也不容易理解。 For my app, these are the following compiler redists and some database related libs: 对于我的应用程序,这些是以下编译器redists和一些数据库相关的libs:

libeay32.dll
libgcc_s_dw2-1.dll
libintl.dll
libpq.dll
libstdc++-6.dll
libwinpthread-1.dl

l

Dependency Walker is always said as a solution for finding this out. Dependency Walker总是被认为是解决这个问题的解决方案。 For me that didn't work either. 对我来说也没用。 Not all of the mentioned libs were listed, but the app isn't running without. 并未列出所有提到的库,但应用程序没有运行。 Maybe it's because the libs are just loaded under special circumstances? 也许是因为libs只是在特殊情况下加载?

addLibraryPath adds a path to the ones that the application will search when dynamically loading libraries. addLibraryPath为动态加载库时应用程序将搜索的路径添加路径。

From the Qt documentation about QCoreApplication::​libraryPaths() : 从关于QCoreApplication::​libraryPaths()的Qt文档:

This list will include the installation directory for plugins if it exists (the default installation directory for plugins is INSTALL/plugins, where INSTALL is the directory where Qt was installed). 此列表将包含插件的安装目录(如果存在)(插件的默认安装目录为INSTALL / plugins,其中INSTALL是安装Qt的目录)。 The directory of the application executable (NOT the working directory) is always added, as well as the colon separated entries of the QT_PLUGIN_PATH environment variable. 始终添加应用程序可执行文件的目录(不是工作目录),以及QT_PLUGIN_PATH环境变量的冒号分隔条目。

Also it's stated in the Qt documentation that : 此外,它在Qt文档中说明:

An application has an applicationDirPath() and an applicationFilePath(). 应用程序具有applicationDirPath()和applicationFilePath()。 Library paths (see QLibrary) can be retrieved with libraryPaths() and manipulated by setLibraryPaths(), addLibraryPath(), and removeLibraryPath(). 可以使用libraryPaths()检索库路径(请参阅QLibrary),并通过setLibraryPaths(),addLibraryPath()和removeLibraryPath()进行操作。

So it seems you can add the path for QLibrary with addLibraryPath . 因此,您似乎可以使用addLibraryPathQLibrary添加路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 QT QcoreApplication postEvent()行为 - QT QcoreApplication postEvent() behaviour Qt蓝牙服务器无法与QCoreApplication一起使用 - Qt Bluetooth server not working with QCoreApplication 我的精神分裂症控制台/ gui Qt5程序应该使用QApplication还是QCoreApplication? - Should my schizophrenic console/gui Qt5 program use QApplication or QCoreApplication? Qt 5.1.0中是否还支持QCoreApplication的aboutToQuit()信号? - Is the aboutToQuit() signal of the QCoreApplication still supported in Qt 5.1.0? 我可以将 QCoreApplication::instance() 用于孤立 QObjects 吗? - Can I use QCoreApplication::instance() for Orphan QObjects? Qt:将QCoreApplication / QNetworkAccessManager与共享动态C ++库结合使用 - Qt: Using QCoreApplication / QNetworkAccessManager with Shared Dynamic C++ Library QT5 错误:未知类型名称“QCoreApplication”。 Qt5 中的第一个程序 - QT5 error: Unknown type name 'QCoreApplication'. First program in Qt5 如何使用 QCoreApplication::postEvent 注入合成输入事件 - How to use QCoreApplication::postEvent to inject synthetic input events 在Linux下运行没有QtCoreApplication / QCoreApplication的Qt C ++代码(Ubuntu 13.10和14.04) - Running Qt C++ code without QtCoreApplication/QCoreApplication under Linux (Ubuntu 13.10 and 14.04) Qt 调试:我如何知道 QCoreApplication::notifyInternal2 正在向哪个对象发送消息? - Qt debugging: How can I know which object QCoreApplication::notifyInternal2 is sending a message to?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM