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!
}
}
}
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.
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.
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.
QML is compiled to an optimized bytecode-like stream and the JavaScript expressions pass through an optimized evaluator for simple expressions.
Inside QML, Qt.application.version
gives the application version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With