diff --git a/QCloudMusicApi/apihelper.cpp b/QCloudMusicApi/apihelper.cpp index 434569f..4108e5d 100644 --- a/QCloudMusicApi/apihelper.cpp +++ b/QCloudMusicApi/apihelper.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -63,7 +64,8 @@ void ApiHelper::afterInvoke(QVariantMap& ret) QVariantMap ApiHelper::invoke(QString member, QVariantMap arg) { - beforeInvoke(arg); + auto connectionType = QThread::currentThread() == this->thread() ? Qt::DirectConnection : Qt::BlockingQueuedConnection; + QMetaObject::invokeMethod(this, [&]() { beforeInvoke(arg); }, connectionType); QVariantMap ret; @@ -79,12 +81,12 @@ QVariantMap ApiHelper::invoke(QString member, QVariantMap arg) } if (useNative) { QMetaObject::invokeMethod(this, member.toUtf8(), - Qt::DirectConnection, - Q_RETURN_ARG(QVariantMap, ret), - Q_ARG(QVariantMap, arg)); + connectionType, + Q_RETURN_ARG(QVariantMap, ret), + Q_ARG(QVariantMap, arg)); } - afterInvoke(ret); + QMetaObject::invokeMethod(this, [&]() { afterInvoke(arg); }, connectionType); return ret; } @@ -102,9 +104,9 @@ QVariantMap ApiHelper::invokeUrl(QString url) arg[queryItem.first] = queryItem.second; } DEBUG << "host" << qurl.host() - << "port" << qurl.port() - << "member" << member - << "arg" << arg; + << "port" << qurl.port() + << "member" << member + << "arg" << arg; return invoke(member, arg); } diff --git a/QCloudMusicApi/definevaluehelper.h b/QCloudMusicApi/definevaluehelper.h index bc0083c..9ed1135 100644 --- a/QCloudMusicApi/definevaluehelper.h +++ b/QCloudMusicApi/definevaluehelper.h @@ -28,42 +28,4 @@ Q_SIGNALS: \ private: \ type m_##valueName = defaultValue; - -#define DEFINE_VALUEADD(type, valueName, defaultValue) \ -Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ -public: \ - type READ_NAME(valueName)() const { return m_##valueName; } \ - void WRITE_NAME(valueName)(type valueName) { \ - if(valueName == 0) { \ - return; \ - } \ - m_##valueName += valueName; \ - emit NOTIFY_NAME(valueName)(); \ - }; \ - void INIT_NAME(valueName)(type valueName){ \ - if(valueName == m_##valueName) { \ - return; \ - } \ - m_##valueName = valueName;\ - emit NOTIFY_NAME(valueName)(); \ - };\ -Q_SIGNALS: \ - void NOTIFY_NAME(valueName)(); \ -private: \ - type m_##valueName = defaultValue; - - -#define DEFINE_VALUE_FORCE(type, valueName, defaultValue) \ -Q_PROPERTY(type valueName READ READ_NAME(valueName) WRITE WRITE_NAME(valueName) NOTIFY NOTIFY_NAME(valueName)) \ -public: \ - type READ_NAME(valueName)() const { return m_##valueName; } \ - void WRITE_NAME(valueName)(type valueName) { \ - m_##valueName = valueName; \ - emit NOTIFY_NAME(valueName)(); \ - } \ -Q_SIGNALS: \ - void NOTIFY_NAME(valueName)(); \ -private: \ - type m_##valueName = defaultValue; - #endif // DEFINEVALUEHELPER_H