QT for Android 使用Item作为QML根对象

来源:互联网 发布:ip 80端口需要备案不 编辑:程序博客网 时间:2024/06/03 19:41

如果将main.qml中的Window替换为Rectangle,再将main.cpp修改成下面的样子;


 #include<QGuiApplication>

//#include <QQmlApplicationEngine>
#include <QQuickView>
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQuickView viewer;
    viewer.setResizeMode(QQuickView::SizeRootObjectToView);
    viewer.setSource(QUrl("qrc:///main.qml"));
    viewer.show();
    return app.exec();
    //QGuiApplication app(argc, argv);
    //QQmlApplicationEngine engine;
    //engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    //return app.exec();
}



这样,在main.xml文件中就可以这样写;

importQtQuick 2.2

//import QtQuick.Window 2.1
Rectangle{
    width:320;
    height: 480;
    color:"red";
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    Text {
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
}

0 0
原创粉丝点击