Solved QQmlApplicationEngine failed to load component
-
Hello, everyone. I came across one problem:
import QtQuick 2.4 import QtQuick.Controls 1.4 import QtQuick.Window 2.2 import NewClass 1.0
The output says:
Starting C:\Users\DELL\Desktop\gicap-zhouyang20180321\debug\gicap-zhouyang20180321.exe... QML debugging is enabled. Only use this in a safe environment. QQmlApplicationEngine failed to load component qrc:/SelectMethodFileWindow.qml:6 module "NewClass" is not installed
This is my main function:
int main(int argc, char *argv[]) { QApplication app(argc,argv); DataSource* dataSource=new DataSource(NULL); qmlRegisterType<NewClass>("NewClass",1,0,"newClass"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/SelectMethodFileWindow.qml"))); engine.rootContext()->setContextProperty("dataSource", dataSource); if (engine.rootObjects().isEmpty()) { return -1; } return app.exec(); }
How to solve that? Could anyone help me?Thanks in advance!
-
@small_bird This page should help you. It explains all of the QML import stuff.
-
@ambershark Thanks a lot, however, my problem is not within the scope.
-
@small_bird It looks like it is to me. I just briefly browsed that link I sent you and found a potential problem right away.
You never check your return code from
qmlRegisterType
.. You may not be successfully registering your type which would account for that error.From the docs http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterType that I linked to from the link I just sent before.
I'm betting that registration is returning a -1 indicating a failure to register.
-
@small_bird Also I can't see the top of your main but are you including
QDeclarativeComponent
? If so try replacing that with a#include <QQuickItem>
and see if that works. -
@small_bird One last idea before I head to bed... Try cleaning and rerunning your build. I've had weirdness like this happen with a dirty build before.
Make sure to rerun cmake or qmake or whatever build you use to refresh your makefiles and then build again and test it.
Hope one of those ideas work, I'm off to bed, good luck! :)
-
@ambershark En, thanks a lot, good night!
-
@ambershark Yes, the return value is -1.
-
@small_bird Yea so if it's -1 that means your registration of that type is failing. Now you just have to figure out why your
NewClass
type is not registering properly and the QML side should start working.I don't see anything obvious from the code you posted, but at least you know where the problem is now. :)
-
@ambershark En, thanks a lot! The problem has been solved: the letter "newCLass" should be "NewCLass". Thanks very much.