简体   繁体   English

在Qt Creator中从.qml文件生成.cpp和.h文件

[英]Generating .cpp and.h file from ..qml file in qt creator

How to generate a .cpp and .h file for login.qml file? 如何为login.qml文件生成.cpp和.h文件?

I have written a .qml file for a login page. 我已经为登录页面编写了一个.qml文件。

my code is as following 我的代码如下

import QtQuick 1.0 导入QtQuick 1.0

Rectangle{
    id:screen
    color: "lightgray"
    width: 3000; height:2700

    Column {
        id: column1
        width: 201
        height: 400

        Row {
            id: row1
            width: 40
            height:50

            TextInput {
                id: userName
                x: 40
                y: 18
                width: 80
                height: 20
                text: qsTr("UserName")
                font.pixelSize: 12
            }

            Rectangle {
                id: rectangle1
                x: 115
                y: 18
                width: 80
                height: 20
                color: "#ffffff"
            }


        }

        Row {
            id: row2
            width: 40
            height: 50

            TextInput {
                id: password
                x: 40
                y: 18
                width: 80
                height: 20
                text: qsTr("Password")
                font.pixelSize: 12
            }

            Rectangle {
                id: rectangle2
                x: 115
                y: 18
                width: 80
                height: 20
                color: "#ffffff"
            }
        }

        Row {
            id: row3
            x: 8
            y: 113
            width: 40
            height: 50

            Rectangle {
                id: rectangle3
                x: 8
                y: 8
                width: 80
                height: 20
                color: "#ffffff"

            Text {
                    id: login
                    text: "Login"
                    x:4
                    y:4
                    width:30
                    height:10
                    font.pixelSize: 12
                }

                   }

        }



    }

    MouseArea {
            anchors.fill: parent
            onClicked: {
                myclass.doStuffFromQmlSlot();

                Qt.quit();
            }
        }

}

That would be quite some work. 那将是很多工作。

You would need to write a C++ code generator or find an existing one. 您将需要编写C ++代码生成器或找到现有的代码生成器。

You would either need to parse the QML code or load it and traverse the tree to feed your code generator. 您可能需要解析QML代码或加载它并遍历树以提供代码生成器。

Your generated code would then either depend on private Qt headers or you need your own implementations for the QtQuick types. 然后,您生成的代码将依赖于私有Qt标头,或者您需要自己的QtQuick类型实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM