What is the difference between QML Rectangle and Window?



  • I create a new Qt Quick application with default basic code. Now if I only replace 'Window' below with`Rectangle', this application never runs..more accurately it runs in the background but GUI never shows up.

    What really is the difference between Window or Rectangle? Why does the application behaviors changes so much that it doesn't even run properly?

    @import QtQuick 2.3
    import QtQuick.Window 2.2

    Window {
    visible: true
    width: 360
    height: 360

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
    

    }@

    The main.cpp file is here

    @#include <QGuiApplication>
    #include <QQmlApplicationEngine>

    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
    return app.exec&#40;&#41;;
    

    }@


Log in to reply
 

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