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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章