Qt World Summit: Register Today!

Promisify QT callbacks to angularjs promise

  • Hi Folks,
    I have started learning AngularJS and QT by my own. And I'm trying to write a promisify function that QT uses to an angularjs $q promise, but can't seem to get my head around it.

    The QT promises are something like:

    method(arg, arg, callback);

    so if C++ had a method that would concatenate two strings the call would be:

    method('A', 'B', function(result) {
      console.log(result);  //would print 'AB'

    I'd like to be able to promisify this method so something like this would work:

    var promiseMethod = $q.promisify(method);
    promiseMethod('A', 'B')
      .then(result) {

    I started adding my decorator, but can't seem to get the actual method calls correct:

    .config(function($provide) {
          $provide.decorator('$q', function($delegate, $rootScope) {
            $delegate.qtPromisify = function(fn) {
              /// ARGH!  what goes here!, this don't work.
              return function() {
                var args = Array.prototype.slice.call(arguments);
                return $delegate(function(resolve, reject) {
                  var result = fn.apply(null, args);
            return $delegate;

    Can anyone share your suggestions on this??

    Thanks & Regards

Log in to reply