QQmlApplicationEngine failed to load component

  • Hello Guy's,
    While building my Qt application I am getting the following error.
    Your kind suggestions are welcome.

    Starting E:\QtCreaterPro\QtCppQml2\debug\QtCppQml2.exe...
    QML debugging is enabled. Only use this in a safe environment.
    QQmlApplicationEngine failed to load component
    qrc:/qml/res/layouts/main.qml:5 Expected type name.

    I am uploading my code , please refer it for further clarification.

    #include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include "datastore.h"
    #include <QtQml>
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
    //    QtQuick2ApplicationViewer viewer;
    //    viewer.setMainQmlFile(QStringLiteral("qml/QtCppQml2/main.qml"));
    //    viewer.showExpanded();
        QQmlApplicationEngine engine;
        QQmlContext* context = engine.rootContext();
        Datastore dt;
       // engine.load(QUrl::fromLocalFile("qml/QtCppQml2/main.qml"));
        return app.exec();

  • Moderators

    @Suraj26254 What is at line no. 5 in main.qml ?

  • @Suraj26254 Seem's like your root component has unknown type or bad name.
    Check that imports contains type of root component and type name don't start with e.g. '_' symbol.

  • @p3c0 Thanks for replying. Below is the code of main.qml.

    //your code here
    `import QtQuick 2.0
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.0
    window {
        visible: true
        width: 100
        height: 62
            target: dataStore
            id: txtCount
            text: "0 Hits"
            id: btnUpdate
            anchors.top: txtCount.bottom
            onClicked:  dataStore.callMeFromQml()

  • Moderators

    @Suraj26254 So according to the code at line no.5 it should be Window rather than window. Note: QML types should begin with captial letters.

  • @Roumed and @p3c0 Thanks a lot for the reply. The problem was with my root component and now error is sloved.
    link text

  • Moderators

    @Suraj26254 Window is the root component here.

  • @p3c0 Ya right. I got it. And now my code is perfect . Thanks

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.