guowenxue
2022-04-08 62e57ba339263e0737ec28418bf3fe730535f675
Add QT hello example source code and build shell script
5 files added
136 ■■■■■ changed files
qt/hello/MainForm.ui.qml 18 ●●●●● patch | view | raw | blame | history
qt/hello/build.sh 22 ●●●●● patch | view | raw | blame | history
qt/hello/main.cpp 12 ●●●●● patch | view | raw | blame | history
qt/hello/main.qml 78 ●●●●● patch | view | raw | blame | history
qt/hello/qml.qrc 6 ●●●●● patch | view | raw | blame | history
qt/hello/MainForm.ui.qml
New file
@@ -0,0 +1,18 @@
import QtQuick 2.5
Rectangle {
    property alias mouseArea: mouseArea
    width: 360
    height: 360
    MouseArea {
        id: mouseArea
        anchors.fill: parent
    }
    Text {
        anchors.centerIn: parent
        text: "Hello World"
    }
}
qt/hello/build.sh
New file
@@ -0,0 +1,22 @@
#!/bin/bash
# export qmake command path
export PATH=$PATH:/apps/qt5_rpi/bin/
# project name is current working directory name
PRJ_NAME=$(basename `pwd`)
# generate project file
rm -f ${PRJ_NAME}.pro
qmake -project
# Add qml support to fix bug: QQmlApplicationEngine: No such file or directory
echo "QT += qml" >> ${PRJ_NAME}.pro
# generate makefile
qmake -makefile ${PRJ_NAME}.pro
# start to cross compile
make && make clean
qt/hello/main.cpp
New file
@@ -0,0 +1,12 @@
#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();
}
qt/hello/main.qml
New file
@@ -0,0 +1,78 @@
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    MainForm {
        anchors.fill: parent
        mouseArea.onClicked: {
            Qt.quit();
        }
        Text {
            id: text1
            x: 131
            y: 136
            width: 100
            height: 20
            text: "192.168.1.10"
            font.pixelSize: 12
        }
        TextInput {
            id: textInput1
            x: 45
            y: 136
            width: 80
            height: 20
            text: "IP地址"
            font.pixelSize: 12
        }
        TextEdit {
            id: textEdit1
            x: 261
            y: 136
            width: 80
            height: 20
            text: qsTr("Text Edit")
            font.pixelSize: 12
        }
        Rectangle {
            id: rectangle1
            x: 380
            y: 165
            width: 200
            height: 200
            color: "#ffffff"
        }
        Image {
            id: image1
            x: 25
            y: 245
            width: 100
            height: 100
            source: "qrc:/qtquickplugin/images/template_image.png"
        }
        Item {
            id: item1
            x: 149
            y: 187
            width: 200
            height: 200
        }
        MainForm {
            id: mainForm1
            x: 163
            y: 52
        }
    }
}
qt/hello/qml.qrc
New file
@@ -0,0 +1,6 @@
<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>MainForm.ui.qml</file>
    </qresource>
</RCC>