| 123456789101112131415161718192021222324252627282930313233 |
- #include "asynchelper.h"
- #include <QDebug>
- AsyncHelper *AsyncHelper::m_instance = nullptr;
- AsyncHelper *AsyncHelper::instance()
- {
- if (!m_instance) {
- m_instance = new AsyncHelper();
- }
- return m_instance;
- }
- AsyncHelper::AsyncHelper(QObject *parent)
- : QObject(parent)
- {}
- // 修改安全执行回调的辅助函数实现
- void safeExecuteCallback(const std::function<void()> &callback, const QString &callbackType)
- {
- if (!callback) {
- qDebug() << "回调函数为空,跳过执行" << callbackType;
- return;
- }
- try {
- callback();
- } catch (const std::exception &e) {
- qWarning() << "执行" << callbackType << "回调时发生异常:" << e.what();
- } catch (...) {
- qWarning() << "执行" << callbackType << "回调时发生未知异常";
- }
- }
|