fix json value crash & timer not work

This commit is contained in:
王劲鹏
2021-04-06 17:58:23 +08:00
committed by osborn
parent fc0af6e992
commit c01bd1e98c
5 changed files with 36 additions and 22 deletions

View File

@@ -11,8 +11,6 @@ DoricBridgeExtension::DoricBridgeExtension(QObject *parent) : QObject(parent) {}
void DoricBridgeExtension::callNative(QString contextId, QString module,
QString methodName, QString callbackId,
QString argument) {
QJsonDocument document = QJsonDocument::fromJson(argument.toUtf8());
QJsonObject jsValue = document.object();
DoricContext *context =
DoricContextManager::getInstance()->getContext(contextId);
bool classRegistered =
@@ -21,7 +19,7 @@ void DoricBridgeExtension::callNative(QString contextId, QString module,
QObject *plugin = context->obtainPlugin(module);
QMetaObject::invokeMethod(plugin, methodName.toUtf8(), Qt::DirectConnection,
QGenericReturnArgument(),
Q_ARG(QJsonObject *, &jsValue),
Q_ARG(QString, argument),
Q_ARG(QString, callbackId));
}
qDebug() << "contextId: " + contextId << "module: " + module

View File

@@ -1,3 +1,4 @@
#include <QCoreApplication>
#include <QTimer>
#include "../utils/DoricConstant.h"
@@ -5,22 +6,29 @@
Q_INVOKABLE void DoricTimerExtension::setTimer(long timerId, int time,
bool repeat) {
QTimer *timer = new QTimer(this);
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, this, [=]() {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
} else {
this->method(timerId);
if (!repeat) {
connect(this, &DoricTimerExtension::startTimer, qApp, [=]() {
QTimer *timer = new QTimer();
timer->setSingleShot(!repeat);
connect(timer, &QTimer::timeout, [=]() {
if (deletedTimerIds->contains(timerId)) {
deletedTimerIds->remove(timerId);
delete timer;
timer->deleteLater();
} else {
this->method(timerId);
if (!repeat) {
deletedTimerIds->remove(timerId);
timer->deleteLater();
}
}
}
});
timer->start(time);
});
timer->start(time);
emit startTimer();
}
Q_INVOKABLE void DoricTimerExtension::clearTimer(long timerId) {

View File

@@ -21,5 +21,8 @@ public:
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat);
Q_INVOKABLE void clearTimer(long timerId);
signals:
void startTimer();
};
#endif // NATIVETIMER_H