File: jsresult.h

package info (click to toggle)
minitube 3.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,600 kB
  • sloc: cpp: 19,800; xml: 68; sh: 18; makefile: 11
file content (35 lines) | stat: -rw-r--r-- 937 bytes parent folder | download
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