我目前正在學習 QtQuick,并且遇到了各種各樣的問題,但這是迄今為止我無法解決的第一個問題。作為背景,我使用的是 MVSC、Visual Studio 2019、CMake 和 Qt6。
?
在運行我的非常基本的程式時,我在我制作module "QtQuick.Controls" is not installed
的main.qml
檔案中的QtQuick Controls 匯入陳述句中遇到錯誤。我正在使用的 CMakeLists.txt 檔案的相關部分是:
?
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
find_package(Qt6 COMPONENTS Quick REQUIRED)
find_package(Qt6 COMPONENTS QuickControls2 REQUIRED)
find_package(Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 COMPONENTS Gui REQUIRED)
qt_add_executable(nameHere
"src/main.cpp"
"gui/main.qml"
)
target_link_libraries(nameHere PRIVATE Qt6::Quick Qt6::QuickControls2)
qt_import_plugins(nameHere QWindowsIntegrationPlugin )
注意:我通過搜索解決方案獲得了一些額外的查找包 - 洗掉或添加 Gui 或 Core 不會更改錯誤
?
檢查構建檔案夾后,這些dll在那里:
- Qt6Gui
- Qt6核心
- Qt6網路
- Qt6OpenGL
- Qt6Qml
- Qt6Qml 模型
- Qt6Quick
?
main.cpp 如下所示:
?
#include <QtQuick>
#include <QtQuickControls2>
int main(int argc, char* argv[])
{
QGuiApplication app(argc, argv);
QQuickView* view = new QQuickView;
view->setSource(QUrl::fromLocalFile("../../gui/main.qml"));
view->show();
return app.exec();
}
main.qml 檔案的內容是
import QtQuick
import QtQuick.Controls
ApplicationWindow {
id: window
width: 400
height: 500
visible: true
}
再次,完整的錯誤是:
?
/gui/main.qml:2:1: module "QtQuick.Controls" is not installed
import QtQuick.Controls
^
/gui/main.qml: module "QtQml.WorkerScript" is not installed
/gui/main.qml:2:1: module "QtQuick.Controls" is not installed
import QtQuick.Controls
^
/gui/main.qml: module "QtQml.WorkerScript" is not installed
任何幫助將不勝感激!
Some further digging through my vcpkg files indicates there is in fact a Qt6QuickControls2.dll that isn't being placed into the build folder. I'm not a fan of just copy and pasting the file into the build folder. I'm not sure why all of the other Qt dlls are being placed into that folder by CMake, but not this specific dll. Is there something that I'm missing from my CMake file, or could this be a bug with how Qt is set up with CMake?
As well, just going ahead and copying the QuickControls2 dll file into the folder doesn't actually fix the problem, so I think there is something else going on here.
好吧,在 Qt6 中,QtQuick 中包含 QucikControls2,所以我不確定它是否真的需要額外的 dll?不確定這里發生了什么,但我什至去運行了 Windeployqt,它說我已經獲得了所有需要的運行時依賴項。現在我不知道這個問題是從哪里來的。
uj5u.com熱心網友回復:
qt_add_executable 中不應鏈接 Qml 檔案。在 Qt6 中,使用
qt_add_qml_module(nameHere
URI gui
VERSION 1.0
QML_FILES gui/main.qml)
請參閱此處的檔案:https : //doc-snapshots.qt.io/qt6-dev/qt-add-qml-module.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/349139.html