Skip to content

tored/qml-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

qml-promise

Promise implementation for JavaScript to C++ in Qt QML

To avoid deep callback chains when doing asynchronous work, use promises.

Before using promises register the QML Engine with Promise::setEngine() (and probably qmlRegisterType)

Requires C++11

Example

C++

QObject* Test::doubleIt(int i)
{
  Promise *promise = new Promise();
  QtConcurrent::run([promise, i] {
    int j = i * 2;
    promise->resolve({i, j});
  });
  return promise;
}

JavaScript

test.doubleIt(5).then(function (i, j) {
  console.log(i, j);
});

TODO

  • Add source code example
  • Try to follow Promise specification somewhat Promises/A+
  • Memory management? Does promise objects get garbaged correctly by the JS GC?
  • Performance?

About

Promise implemenation for JavaScript to C++ in Qt QML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages