可以通过捕获异常来避免程序退出,可以使用try-catch语句:

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

    try {
        // Your code here
    } catch (const std::exception& e) {
        qDebug() << "Exception caught: " << e.what();
    }

    return app.exec();
}

在try块中编写的代码可能会抛出异常,如果发生异常,控制权将传递到catch块。在catch块中,可以处理异常,例如打印错误消息并继续执行程序。

如何让QT异常时不退出

原文地址: https://www.cveoy.top/t/topic/coW7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录