gpt4 book ai didi

QtQuick,如何知道应用程序是在 Debug模式还是 Release模式下编译的?

转载 作者:行者123 更新时间:2023-12-04 10:04:09 31 4
gpt4 key购买 nike

在 Qt/C++ 中有 QT_DEBUG 定义宏来知道它何时在调试或发布时编译。

有什么方法可以知道应用程序是否在 QML 文件中以调试或 Release模式运行?

最佳答案

您可以使用 context properties将 C++ 对象暴露给 QML:

#include <QtGui/QGuiApplication>
#include <QQmlContext>
#include <QQuickView>
#include "qtquick2applicationviewer.h"

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

QtQuick2ApplicationViewer viewer;
#ifdef QT_DEBUG
viewer.rootContext()->setContextProperty("debug", true);
#else
viewer.rootContext()->setContextProperty("debug", false);
#endif
viewer.setMainQmlFile(QStringLiteral("qml/quick/main.qml"));
viewer.showExpanded();

return app.exec();
}

主.qml:
import QtQuick 2.2

Item {
id: scene
width: 360
height: 360

Text {
anchors.centerIn: parent
text: debug
}
}

不可能完全从 QML 中确定这一点。

关于QtQuick,如何知道应用程序是在 Debug模式还是 Release模式下编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22905918/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com