benlau / quickpromise

Quick Promise - QML Promise Library
Apache License 2.0
179 stars 26 forks source link

Return promise from C++ #3

Closed nathanielhourt closed 8 years ago

nathanielhourt commented 8 years ago

Have you attempted to create and resolve these promises from C++, returning them to QML so QML can be notified when asynchronous C++ operations finish? How hard is it to do this?

nathanielhourt commented 8 years ago

Well after much experimentation, I answered my own question. I've created a class, QmlPromise, which can be created from C++ and creates a Promise{} component and mirrors its API in C++ friendly signals and slots. I haven't figured out how to implement then(onResolve, onReject) in C++ since I'm not sure how to pass a C++ function to javascript as a value. It's not necessary for my purposes anyways.

I'll close this issue with a link to that class when I post it on Github, in case you'd like to add it to this repo.

nathanielhourt commented 8 years ago

See: https://github.com/benlau/quickpromise/pull/4