我在*.pro项目文件中定义了这个宏:
# The application version
VERSION = 6.10.0
# Define the preprocessor macro to get the application version in our application.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
Run Code Online (Sandbox Code Playgroud)
然后我设置我的应用程序版本如下:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
/*
* Setting the Application version
*/
app.setApplicationVersion(APP_VERSION);
// ...
}
Run Code Online (Sandbox Code Playgroud)
现在我想访问共享库中的QML代码中的应用程序版本.我怎样才能做到这一点?:
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!
}
}
}
Run Code Online (Sandbox Code Playgroud)