【发布时间】:2017-05-06 20:27:47
【问题描述】:
我需要(例如在构建库时)在堆上实例化 QCoreApplication,我发现了以下奇怪的行为(Qt 5.7):
#include <QCoreApplication>
#include <QDebug>
class Test
{
public:
Test(int argc, char *argv[]) {
m_app = new QCoreApplication(argc, argv);
//uncomment this line to make it work
//qDebug() << "test";
}
~Test() { delete m_app; }
private:
QCoreApplication* m_app;
};
int main(int argc, char *argv[])
{
Test test(argc, argv);
qDebug() << QCoreApplication::arguments(); //empty list!
}
基本上,如果在分配对象后使用“qDebug()”,一切都会按预期工作。如果不是,arguments() 的列表为空。
【问题讨论】: