7

I have an app that its project generated using CMake in Qt5.7, so when import QtQuick.Controls 2.0 application failed to load with the following error:

plugin cannot be loaded for module "QtQuick.Controls": Cannot load library C:\Qt\Qt5.7.0\5.7\msvc2015\qml\QtQuick\Controls.2\qtquickcontrols2plugind.dll: The specified module could not be found.

CMakeLists.txt

set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.7.0\\5.7\\msvc2015")
set(CMAKE_AUTOMOC ON) 
set(CMAKE_AUTORCC ON) 
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Qml) 
find_package(Qt5Quick) 
find_package(Qt5QuickControls2)

...

add_executable(MyApp ${SRC} ${HEADER} ${RESOURCES})

target_link_libraries(MyApp
Qt5::WinMain    
Qt5::Core   
Qt5::Qml    
Qt5::Quick  
Qt5::QuickControls2     
)

The DLL file loaded in visual studio output:

'MyApp.exe' (Win32): Loaded 'C:\Qt\Qt5.7.0\5.7\msvc2015\qml\QtQuick.2\qtquick2plugind.dll'. Symbols loaded.
'MyApp.exe' (Win32): Loaded 'C:\Qt\Qt5.7.0\5.7\msvc2015\qml\QtQuick\Controls.2\qtquickcontrols2plugind.dll'. Symbols loaded.
'MyApp.exe' (Win32): Unloaded 'C:\Qt\Qt5.7.0\5.7\msvc2015\qml\QtQuick\Controls.2\qtquickcontrols2plugind.dll'
4

3 回答 3

10

我找到了解决方案,问题QtQuick.Controls 2.0取决于QtQuick.Templates 2.0模块,因此我已将其 dll 复制到输出目录并成功运行。

所需的 DLL(用于调试版本):

Qt5QuickTemplates2d.dll
Qt5QuickControls2d.dll

所需的 DLL(对于发布版本):

Qt5QuickTemplates2.dll
Qt5QuickControls2.dll
于 2016-06-25T16:42:32.680 回答
2

在 Windows 上,Qt 提供了自动扫描所有 Qt 和 QML 依赖项的部署工具:

%QTDIR%\bin\windeployqt.exe your_app.exe --qmldir your\qml\files

请参阅 Qt 文档:

该工具可以在 QTDIR/bin/windeployqt 中找到。它以 .exe 文件或包含 .exe 文件的目录作为参数,并扫描可执行文件的依赖项。如果使用 --qmldir 参数传递目录,windeployqt 使用 qmlimportscanner 工具扫描目录中的 QML 文件以查找 QML 导入依赖项。然后将识别的依赖项复制到可执行文件的目录中。Qt5Core.dll 中硬编码的本地路径被替换为相对路径。

于 2017-06-21T12:34:16.370 回答
1

如果您使用的是 Ubunty,请尝试安装 qml-module-qtquick-controls2

sudo apt install qml-module-qtquick-controls2
于 2020-06-08T12:24:04.317 回答