QmlTask
Module | Qml |
---|---|
Include |
|
CMake |
|
QMake |
|
QmlTask allows to return QCoro::Tasks directly to QML. It can be constructed from any QCoro::Task that returns a value that can be converted to a QVariant.
#include <QCoroQml>
#include <QCoroQmlTask>
int main()
{
...
qmlRegisterType<Example>("io.me.qmlmodule", 1, 0, "Example");
QCoro::Qml::registerTypes();
...
}
class Example : public QObject
{
Q_OBJECT
...
public:
Q_INVOKABLE QCoro::QmlTask fetchValue(const QString &name) const
{
return database->fetchValue(name);
// Returns QCoro::Task<QString>
}
}
Example {
Component.onCompleted: {
fetchValue("key").then((result) => console.log("Result", result))
}
}