Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Promisify QT callbacks to angularjs promise
Forum Updated to NodeBB v4.3 + New Features

Promisify QT callbacks to angularjs promise

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 248 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TejaswiniUL
    wrote on 21 Jul 2018, 06:28 last edited by TejaswiniUL
    #1

    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) {
         console.log(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);
                  resolve(result);
                });
              }
            };
            return $delegate;
          });
        })
    

    Can anyone share your suggestions on this??

    Thanks & Regards
    Tejaswini

    1 Reply Last reply
    0

    1/1

    21 Jul 2018, 06:28

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved