Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQMLComponent not showing up in main Window



  • Hi there, I am following the documentation to call a QML component from c++ and display it in the main window: http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

    In main.cpp i have the following:

    QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        QQmlComponent component(&engine,
                QUrl::fromLocalFile(":/Circle2.qml"));
        QObject *object = component.create();
    

    The path ":/Circle2.qml" as opposed to "Circle2.qml" or "qrc:/Circle2.qml" is the only path that does not generate the error "QQmlComponent: Component is not ready" as described in this post: https://forum.qt.io/topic/54517/solved-qqmlcomponent-component-is-not-ready/9

    HOWEVER, even without the error, the Circle component does not show up in my main window.

    my main.qml:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 300
        title: qsTr("Hello World")
        color: "green"
    
    
        /*Circle{
            //width: parent.width/16
            //height: parent.height/8
            anchors.centerIn: parent
        }*/
    
    }
    

    and my Circle2.qml file:

    import QtQuick 2.4
    
    Rectangle{
            width: 50
            height: 50
             color: "darkblue"
             //border.color: "blue"
             border.width: 0
             radius: width*0.5
    
    }
    

    Does anyone know why my circle isnt displaying anywhere?



  • This is all I see when i run it:

    0_1537307208470_Screen Shot 2018-09-18 at 5.46.37 PM.png


Log in to reply