Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access application version from within QML

Tags:

qt

qml

I have defined this macro in my *.pro project file:

# The application version
VERSION = 6.10.0

# Define the preprocessor macro to get the application version in our application.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"

Then I set my application version like this:

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

    /*
     * Setting the Application version
     */
    app.setApplicationVersion(APP_VERSION);

    // ...

}

Now I want to access the application version inside my QML code which is in a shared library. How can I do that? :

    ColumnLayout {
        id: versionLayout

        StyledLabel {
            text: qsTr("Version")
            font.weight: Font.Bold
        }
        RowLayout {
            StyledLabel {
                Layout.alignment: Qt.AlignCenter
                text: APP_VERSION // How can I access my macro/version here?
                                  //  QApplication.applicationVersion() is NOT working!
            }
        }
    }
like image 506
user3405291 Avatar asked Nov 11 '18 10:11

user3405291


People also ask

What is the difference between Qt and QML?

QML is the language; its JavaScript runtime is the custom V4 engine, since Qt 5.2; and Qt Quick is the 2D scene graph and the UI framework based on it. These are all part of the Qt Declarative module, while the technology is no longer called Qt Declarative.

How do I run a QML application?

Creating and Running QML Projects For simple UI files such as this one, select File > New File or Project > Application (Qt Quick) > Qt Quick Application - Empty from within Qt Creator. Pressing the green Run button runs the application. You should see the text Hello, World! in the center of a red rectangle.

What is a QML application?

QML is a user interface specification and programming language. It allows developers and designers alike to create highly performant, fluidly animated and visually appealing applications.

Is QML compiled?

QML is compiled to an optimized bytecode-like stream and the JavaScript expressions pass through an optimized evaluator for simple expressions.


1 Answers

Inside QML, Qt.application.version gives the application version.

like image 166
user3405291 Avatar answered Sep 21 '22 15:09

user3405291