gpt4 book ai didi

qt - QCoreApplication退出不工作

转载 作者:行者123 更新时间:2023-12-04 13:06:33 25 4
gpt4 key购买 nike

我已经创建了一个控制台程序。出于调试目的,如果不满足某些条件,我需要程序退出。这是一个例子:

if (VDD.isEmpty() || GND.isEmpty()){
qWarning() << "VDD and GND must NOT be empty";
QCoreApplication::quit();
qWarning() << "After the quit";
}

据我了解,不应打印 quit() 之后的输出。

我程序的main()函数是这样的:

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

// Do stuff that calls the code above

return a.exec();
}

谁能告诉我为什么会这样?

目前我正在使用abort(),但我更愿意使用quit()

最佳答案

quit() 导致事件循环在下一次获得控制权时返回。它不会立即返回。所以你需要类似的东西

QCoreApplication::quit();
return;

或者如果您使用的是不是直接从 Qt 调用的方法,则可能更复杂一些。

相关exit()方法的文档说:

Note that unlike the C library function of the same name, this function does return to the caller -- it is event processing that stops.

关于qt - QCoreApplication退出不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45214178/

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