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 Update on Monday, May 27th 2025

Promisify QT callbacks to angularjs promise

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 247 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 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

    • Login

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