-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose QPromise to QML #5
Comments
@Adphi Thank you :) What do you mean exactly by "... support QPromise exposition to QML"? I started writing a QML wrapper allowing to use the same functionalities in JavaScript: var promise = new Promise(function(resolve) {
//...
resolve(42);
});
promise
.then(function(res) { /*...*/ })
.fail(function(err) { /*...*/ })
.finally(function() { /*...*/ })
// ... Internally, it relies on a |
I mean: exchanging promises between C++ and QML. class CustomObjectWithPromise : public QObject
{
Q_OBJECT
public:
explicit CustomObjectWithPromise(QObject *parent = nullptr);
Q_INVOKABLE QtPromise::QPromise<int>* getIntAsync();
signals:
public slots:
private:
QNetworkAccessManager *mManager;
}; |
Then, we need to figure out how to convert from/to class CustomObjectWithPromise : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QtPromise::QJSPromise getIntAsync();
{
// readIntValueAsync returning QPromise<int>
return readIntValueAsync().as<QJSValue>();
}
}; Note: QPromise has been designed to avoid dealing with pointers, you shouldn't return a |
Thank you. |
@simonbrunel What is the biggest issue to solve for getting QML Promise in a technology preview state? As in knowing full well that the API may change, but being confident that then/fail/finally do what you would expect? I've seen there are some automated tests in the wip branch covering the behavior within QML already. Wouldn't it be save to use within QML then? Do you like the idea of having a generic |
The major issue is accessing the current Currently, it should be relatively easy to release a QML only implementation where the QJSPromise would be private and always bound to a I already implemented |
WIP on the Qt side for a native JavaScript promise: https://codereview.qt-project.org/#/c/122066/ |
Interesting, sounds like they are almost at the point of merging ES6 Promises into their JS engine. Crazy thought: Could this be an opportunity to use that momentum and convince Lars Knoll to include your library to follow up on this development on the C++ side? As TP of some sort? The point being that if both worlds had a reference Promise implementation, the QML engine might as well just implement automatic conversion from/to those types instead of being forced to shoehorn everything through QObject/Gadget/QJSValue. Like they did with supporting QByteArray <-> ArrayBuffer at some point. |
So since creating |
@pwuertz FYI, a C++ promise like API is under investigation for Qt 6 (QTBUG-80908). |
Hi !
First: thanks for your beautiful work on this.
Is there any plan to support QPromise exposition to QML ?
The text was updated successfully, but these errors were encountered: