发布时报 Please instantiate the QApplication object first

gucunlin gucunlin 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在Debug下正常,在relase下时报QCoreApplication::applicationDirPath: Please instantiate the QApplication object first错误
这是有QCoreapplication里面出来的,我的main如下

int main(int argc, char *argv[])
{
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
Q_INIT_RESOURCE(images);
QTranslator oTranslator;
oTranslator.load(":/qt_zh_CN");
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}
也没有什么特别的地方
在QCoreApplication.cpp里有个函数检查报出来的
如下


bool QCoreApplicationPrivate::checkInstance(const char *function)
{
bool b = (QCoreApplication::self != 0);
if (!b)
qWarning("QApplication::%s: Please instantiate the QApplication object first", function);
return b;
}
程序里确实使用了很多applicationDirPath(),唯有一个类使用时报这个,把那个类注释掉就不报了,什么意思呢,我是在主窗体的TimerEvent里初始化的那个类。总不能给个Debug版本让别人用吧。
那个类只是有cpp上引用 了#include <QCoreApplication> 后面使用了许多QCoreApplication:: applicationDirPath()
这个用法没什么错呀,怎么解决呢

...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
gucunlin
Qt 21,505 成员 26,693 内容