2015-02-06 132 views
1

我嘗試註冊的類型,但我得到這個錯誤:錯誤:QQmlApplicationEngine未能加載組件

QQmlApplicationEngine failed to load component 
qrc:/main.qml:5 module "Komut" is not installed

這是我使用的代碼:

QQmlApplicationEngine engine; 
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 
qmlRegisterType<Execom>("Komut",1,0,"Execom"); 
+2

加載引擎後,您似乎註冊了類型。 – cmannett85 2015-02-06 15:48:39

+0

^這可能是問題所在。經常會發生在我身上。 :D – Mitch 2015-02-06 16:17:00

+0

那麼,有沒有解決方案?或者,這只是一個錯誤或水手。 – oksidez 2015-02-06 16:32:17

回答

3

代替這樣的:

QQmlApplicationEngine engine; 
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 
qmlRegisterType<Execom>("Komut",1,0,"Execom"); 

這樣做:

qmlRegisterType<Execom>("Komut",1,0,"Execom"); 
QQmlApplicationEngine engine; 
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 
+0

非常感謝@ cmannett85 – oksidez 2015-02-09 15:41:34

+0

當爲android構建時,無法加載'QQmlApplicationEngine無法加載組件'。 – 2017-01-02 04:57:06