1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#ifndef JSRESULT_H
#define JSRESULT_H
#include <QtQml>
class JSResult : public QObject {
Q_OBJECT
public:
JSResult(QObject *parent = nullptr) : QObject(parent) {}
~JSResult() { qDebug() << "Destroying result"; }
template <typename Functor> JSResult &onString(Functor lambda) {
connect(this, &JSResult::string, this, lambda);
return *this;
}
template <typename Functor> JSResult &onJson(Functor lambda) {
connect(this, &JSResult::json, this, lambda);
return *this;
}
template <typename Functor> JSResult &onError(Functor lambda) {
connect(this, &JSResult::error, this, lambda);
return *this;
}
Q_INVOKABLE QJSValue setData(QJSValue value);
Q_INVOKABLE QJSValue setError(QJSValue value);
signals:
void json(const QJsonDocument &doc);
void string(const QString &data);
void error(const QString &message);
};
#endif // JSRESULT_H
|