Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt6 QML QQmlApplicationEngine failed to load component error

Qt6 QML QQmlApplicationEngine failed to load component error

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 647 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Habib123H Offline
    Habib123H Offline
    Habib123
    wrote on last edited by Habib123
    #1

    I want to use component in QtQuick, i have two qml files one is main.qml and the second button.qml, and iam using this example for their documentation, but when i run my code it is giving me error that QQmlApplicationEngine failed to load component qrc:/bbb/main.qml:13:5: Button is not a type. also iam seeing some red error in the imported Button in main.qml. even i have removed the signal functionalities and i have just used the simple button, but again the same error, and also the same example with same structure works in qt5, but in qt6 it is not working.

    main.qml

    import QtQuick
    
        Window {
            id:root
             width: 640
             height: 480
             visible: true
             title: qsTr("Hello World")
        
        
            Button { // our Button component
                id: button
                x: 12; y: 12
                text: "Start"
                onClicked: {
                    status.text = "Button clicked!"
                }
            }
        
            Text { // text changes when button was clicked
                id: status
                x: 12; y: 76
                width: 116; height: 26
                text: "waiting ..."
                horizontalAlignment: Text.AlignHCenter
            }
        
        }
    

    Button.qml

    import QtQuick 2.0
    
    Item {
        Rectangle {
            id: root
            // export button properties
            property alias text: label.text
            signal clicked
    
            width: 116; height: 26
            color: "lightsteelblue"
            border.color: "slategrey"
    
            Text {
                id: label
                anchors.centerIn: parent
                text: "Start"
            }
            MouseArea {
                anchors.fill: parent
                onClicked: {
                    root.clicked()
                }
            }
        }
    
    }
    

    main.cpp

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        const QUrl url(u"qrc:/bbb/main.qml"_qs);
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        engine.load(url);
    
        return app.exec();
    }
    

    alt text

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved