Qt开发 — QtQuick无法加载

简述

在做Qt QML QML 程序开发的时候,当切换啦电脑,重新安装啦QT Create。但是在调试程序的时候,会莫名奇妙的报错QtQuick 未被安装等。如下错误:

QQmlApplicationEngine failed to load component
qrc:/main.qml:1 module "QtQuick.Controls" is not installed
qrc:/main.qml:2 module "QtQuick" is not installed
qrc:/main.qml:1 module "QtQuick.Controls" is not installed

原因

在加载QtQuick的时候,使用Qt静态库无法找到qml。

解决方案

直接在程序里面指明qml加载的路径

int main(int argc, char *argv[])
{
	QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    //engine.addImportPath("/Users/gjh/Qt5.12.0/5.12.0/clang_64/qml");
    engine.addImportPath("../../../Qt5.12.0/5.12.0/clang_64/qml");
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
	if (engine.rootObjects().isEmpty())
		return -1;
    return app.exec();
}

协同开发,尽量使用相对路径。

发布了85 篇原创文章 · 获赞 27 · 访问量 10万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章