Quick Future v1.0.3 has been released. This version supports a custom type converter for making a QML friendly data structure from QFuture<YourCustomType>. Calling an async function and obtain the result from QML on a C++ class is much easier now.
New Features
Custom Converter function
QuickFuture::registerType() now supports to assign a custom converter for making a QML friendly data structure (e.g QVariantMap) from the custom type. The value could be obtained by using Future.result()
class Actor : public QObject {
Q_OBJECT
public:
class Reply {
public:
int code;
QString message;
};
QFuture<Reply> read(QString source);
}
static void init() {
QuickFuture::registerType<Actor::Reply>([](Actor::Reply reply) -> QVariant {
// Optional converter function.
QVariantMap map;
map["code"] = reply.code;
map["message"] = reply.message;
return map;
});
}
Q_COREAPP_STARTUP_FUNCTION(init)
var future = Actor.read(source);
....
console.log(Future.result(future)); // Print { code: 0, message: ""} if the reply is empty