我正在尝试使用CMake在Visual Studio中构建QML项目。这是我的文件:
CMakeLists.txt
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(MyProject)
find_package(Qt5 COMPONENTS Quick Core Network)
find_package(Qt5QuickCompiler)
qtquick_compiler_add_resources(RESOURCES qml.qrc)
add_executable(MyExec main.cpp ${RESOURCES})
qt5_use_modules(MyExec Quick Core Network)
main.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtPositioning 5.11
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char* argv[]) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
qml.qrc
<RCC>
<qresource prefix="/">
<file>main.qml</file>
</qresource>
</RCC>
构建并运行它时,我得到了:
QQmlApplicationEngine failed to load component
qrc:/main.qml:3 plugin cannot be loaded for module "QtPositioning": Cannot load library D:\Dev\MyProject\build\bin\qml\QtPositioning\declarative_positioningd.dll: The specified module could not be found.
但是,当我转到该目录时,则存在declarative_positioningd.dll。在网上唯一可以找到与该问题类似的东西是here。他们说他们通过缺少Qt5PositioningQuick.dll文件解决了他们的问题,但是该文件也存在于相关的Qt5安装目录中,我也尝试将其放在带有declarative_positioningd.dll的文件夹中无济于事。
这个问题是QtPositioning特有的,我尝试过的其他QML导入似乎都可以正常工作(QtLocation除外,后者取决于QtPositioning)。