【发布时间】:2019-10-02 14:13:33
【问题描述】:
我正在尝试运行
qputenv("QT_DEBUG_PLUGINS", "1");
在 QT 应用程序的 MainWindow 进行评估之后的运行时。
我假设要实际应用新的环境变量,我必须关闭初始化的 QApplication 并重新启动它,但我无法使其工作。
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
int exitCode = 0;
do
{
//exitCode = EXIT_CHANGE_DEBUG_FLAG; //This will make it ALWAYS work
//Double-checking for testing only, still does not work.
if(exitCode == EXIT_CHANGE_DEBUG_FLAG)
{
qputenv("QT_DEBUG_PLUGINS", "1"); // Code does fire on 2nd pass, new app/window still ignores it
}
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
exitCode = app.exec();
//We can't change this once the app has been established.
qputenv("QT_DEBUG_PLUGINS", "1");
exitCode = EXIT_CHANGE_DEBUG_FLAG; //for testing only
}
while(exitCode == EXIT_CHANGE_DEBUG_FLAG);
return(exitCode);
}
应用程序确实重新启动,但它的行为不像设置了 QT_DEBUG_PLUGINS。如果我将该行移到 QApplication 上方,它总是可以工作,但我希望这是一个在运行时可用的配置选项。
我觉得我要么在尝试做不可能的事情,要么我忽略了一些愚蠢的事情。
【问题讨论】:
标签: c++ qt environment-variables qt5 qapplication