2016-06-25 32 views
3

Ich habe eine Anwendung, die ihr Projekt CMake in Qt5.7 erzeugt wird, so, wenn import QtQuick.Controls 2.0 Anwendung konnte nicht mit dem folgenden Fehler laden:Import QtQuick.Controls 2.0 funktioniert nicht - QQmlApplicationEngine ausgefallene Komponente laden

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  
) 

Die DLL geladene Datei in Visual Studio Ausgabe:

'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' 
+0

Welche Dateien haben Sie in 'C: \ Qt \ Qt5.7.0 \ 5.7 \ msvc2015 \ qml \ QtQuick \ Controls.2'? Es sieht so aus, als würde es versuchen, die Debug-Version des Plugins zu finden, aber hat deine Qt-Installation es verfügbar? – jpnurmi

+0

Ja, es ist die DLL-Datei im Pfad und geladen in Visual Studio (ich sehe in der Intellisense, ihre Symbole geladen), aber App nicht geladen werden. –

+1

Aus irgendeinem Grund entlädt es das Plugin sofort? Ich weiß nicht, was das verursachen könnte. Was passiert, wenn Sie das Plugin mit Dependency Walker öffnen? Ist dies eine vorgefertigte Qt-Installation von einem Installer? Wenn ja, funktioniert das Qt Quick Controls 2 Gallery-Beispiel? – jpnurmi

Antwort

4

Ich fand die Lösung, das Problem ist QtQuick.Controls 2.0 hängt von QtQuick.Templates 2.0 Modul ab, also habe ich seine DLL zum Ausgabeverzeichnis kopiert und es läuft erfolgreich.

benötigt DLLs (für Debug-Version):

Qt5QuickTemplates2d.dll 
Qt5QuickControls2d.dll 

benötigt DLLs (für Release-Version):

Qt5QuickTemplates2.dll 
Qt5QuickControls2.dll 
+0

Kann Qt's CMake-Integration automatisch ausgeführt werden? Ist es normal, dass Sie die gesamte Abhängigkeitskette von Hand auflisten müssen? Oder ist es vielleicht eine fehlende Abhängigkeitsdeklaration irgendwo in QQC2? – jpnurmi

+0

Tatsächlich habe ich gerade bemerkt, dass QtGui und QtXmlPatterns auch nicht explizit aufgeführt sind, so dass Abhängigkeiten zu einem gewissen Grad aufgelöst werden müssen. – jpnurmi

0

Unter Windows Qt bietet Deployment-Tool, das alle Qt und QML Abhängigkeiten automatisch durchsucht:

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

See the Qt documentation:

The tool can be found in QTDIR/bin/windeployqt. It takes an .exe file or a directory that contains an .exe file as an argument, and scans the executable for dependencies. If a directory is passed with the --qmldir argument, windeployqt uses the qmlimportscanner tool to scan QML files inside the directory for QML import dependencies. Identified dependencies are then copied to the executable's directory. The hardcoded local paths in Qt5Core.dll are furthermore replaced with relative ones.