andersch.dev

<2024-11-20 Wed>

Qt

Qt is a cross-platform application and UI framework.

qmake

The build system tool of the Qt framework is qmake. It uses .pro files as configuration files. These contain settings for building Qt applications, such as source/header files, libraries, and required modules. They also specify target platform, compiler options, and resource files. Qmake uses this information to generate project files (such as a Makefile).

QML

The Qt Modeling Language (QML) is a declarative programming language for building UIs in Qt applications. In QML, the structure and behavior of the UI is defined using a JSON-like syntax. It can be used with JavaScript for more interactivity.

QML Code Example: Show "Hello World" on button press

import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow {
    visible: true
    width: 400
    height: 200
    title: "Hello World Example"

    // A property to control the visibility of the text
    property bool showText: false

    Column {
        anchors.centerIn: parent
        spacing: 20

        Button {
            text: "Press me"
            onClicked: {
                showText = true  // Set the property to true when the button is clicked
            }
        }

        Text {
            text: "Hello, World!"
            visible: showText  // Show the text only if showText is true
            font.pointSize: 24
        }
    }
}
#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();
}