【问题标题】:Access application version from within QML从 QML 中访问应用程序版本
【发布时间】:2018-11-11 10:07:50
【问题描述】:

我已经在我的*.pro 项目文件中定义了这个宏:

# The application version
VERSION = 6.10.0

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

然后我像这样设置我的应用程序版本:

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

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

    // ...

}

现在我想访问我的 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!
            }
        }
    }

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    在 QML 内部,Qt.application.version 给出应用程序版本。

    【讨论】:

    • 其他宏呢?
    猜你喜欢
    • 2016-01-03
    • 1970-01-01
    • 2020-04-26
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 2011-03-21
    • 1970-01-01
    相关资源
    最近更新 更多