55
66#include < QMetaMethod>
77#include < QPluginLoader>
8+ #include < QThread>
89#include < QUrl>
910#include < QUrlQuery>
1011
@@ -63,7 +64,8 @@ void ApiHelper::afterInvoke(QVariantMap& ret)
6364
6465QVariantMap ApiHelper::invoke (QString member, QVariantMap arg)
6566{
66- beforeInvoke (arg);
67+ auto connectionType = QThread::currentThread () == this ->thread () ? Qt::DirectConnection : Qt::BlockingQueuedConnection;
68+ QMetaObject::invokeMethod (this , [&]() { beforeInvoke (arg); }, connectionType);
6769
6870 QVariantMap ret;
6971
@@ -79,12 +81,12 @@ QVariantMap ApiHelper::invoke(QString member, QVariantMap arg)
7981 }
8082 if (useNative) {
8183 QMetaObject::invokeMethod (this , member.toUtf8 (),
82- Qt::DirectConnection ,
83- Q_RETURN_ARG (QVariantMap, ret),
84- Q_ARG (QVariantMap, arg));
84+ connectionType ,
85+ Q_RETURN_ARG (QVariantMap, ret),
86+ Q_ARG (QVariantMap, arg));
8587 }
8688
87- afterInvoke (ret );
89+ QMetaObject::invokeMethod ( this , [&]() { afterInvoke (arg); }, connectionType );
8890
8991 return ret;
9092}
@@ -102,9 +104,9 @@ QVariantMap ApiHelper::invokeUrl(QString url)
102104 arg[queryItem.first ] = queryItem.second ;
103105 }
104106 DEBUG << " host" << qurl.host ()
105- << " port" << qurl.port ()
106- << " member" << member
107- << " arg" << arg;
107+ << " port" << qurl.port ()
108+ << " member" << member
109+ << " arg" << arg;
108110 return invoke (member, arg);
109111}
110112
0 commit comments