Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Quick Promise - QML Promise Library

Quick Promise - QML Promise Library

Scheduled Pinned Locked Moved QML and Qt Quick
promise
8 Posts 3 Posters 5.7k 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.
  • B Offline
    B Offline
    benlau
    Qt Champions 2016
    wrote on 22 May 2015, 17:56 last edited by
    #1

    Hi,

    In case you are looking for a Promise library that works well with QML , I would like to share my latest open source project with you. Its name is “Quick Promise”. It is a library that provides Promise object in QML way. It comes with a Promise component with signal and property. It could be resolved via a binary expression , another promise object, then trigger your callback by QueuedConnection.

    Moreover, it also provides Promise as Javascript object that don’t need to declare in QML way. The API is fully compliant with Promises/A+ specification (Passed all the test cases) and therefore it just works like many other Promise solutions for Javascript application.

    Example:

    
    Promise {
        resolveWhen: !someService.running // Once the expression become truth , the onFulfilled signal will be triggered via QueuedConnection
        onFulfilled: { 
        }
    }
    
    Promise {
        rejectWhen: timer.onTriggered  // Reject after timeout
       onRejected: {
       }
    }
    

    The project link: QuickPromise

    Enjoy it.

    1 Reply Last reply
    3
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 22 May 2015, 23:02 last edited by
      #2

      Hi,

      You project reminds me of AngularJS. Looks pretty interesting ! Thanks for sharing

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply 15 Jun 2015, 16:33
      0
      • S SGaist
        22 May 2015, 23:02

        Hi,

        You project reminds me of AngularJS. Looks pretty interesting ! Thanks for sharing

        B Offline
        B Offline
        benlau
        Qt Champions 2016
        wrote on 15 Jun 2015, 16:33 last edited by
        #3

        @SGaist Thx

        haha, you also reminds me the time when I shift from AngularJS to QML. I tried to understand/write QML in an AngularJS way. Look for a solution of "Transclude" in QML. Assume the item in ListModel support 2 way data binding...

        1 Reply Last reply
        0
        • B Offline
          B Offline
          benlau
          Qt Champions 2016
          wrote on 17 Jul 2015, 04:37 last edited by
          #4

          v1.0.2 has been just released. Now user could resolve a promise by multiple signals and binary expression!

          Example

          1. Resolve by multiple signals.
          
          Promise {
              resolveWhen: Q.all([timer.triggered, loader.loaded]);
          }
          
          
          1. Resolve by signal and binary expression
          Promise {
              resolveWhen: Q.all([timer.triggered, promise2]);
          
              Promise {
                  id : promise2
                  resolveWhen: image.status === Image.Ready
              }
          }
          
          
          1 Reply Last reply
          0
          • B Offline
            B Offline
            benlau
            Qt Champions 2016
            wrote on 17 Nov 2015, 07:38 last edited by
            #5

            Quick Promise is now available at qpm.io . You could install latest version (1.0.2) via qpm install com.github.benlau.quickpromise

            1 Reply Last reply
            0
            • B Offline
              B Offline
              benlau
              Qt Champions 2016
              wrote on 15 Feb 2016, 16:16 last edited by
              #6

              v1.0.3 released.

              Changes

              1. The resolve parameter to promise generated by Q.all() become an array of results of original promises
              1 Reply Last reply
              0
              • C Offline
                C Offline
                cp_mark
                wrote on 7 Mar 2018, 16:16 last edited by
                #7

                This looks pretty promising (pun possibly intended).
                I've been looking for something like this to avoid callback hell. However, I need to resolve/reject based off an argument in a signal.

                ie.

                Item {
                        id: obj
                        signal done(bool success)
                }
                Promise {
                        id : signalArgPromise
                        resolveWhen: obj.done(success === true)
                        rejectWhen: obj.done(success === false)
                }
                

                Would it be possible to do something like this using your library?

                B 1 Reply Last reply 7 Mar 2018, 17:24
                0
                • C cp_mark
                  7 Mar 2018, 16:16

                  This looks pretty promising (pun possibly intended).
                  I've been looking for something like this to avoid callback hell. However, I need to resolve/reject based off an argument in a signal.

                  ie.

                  Item {
                          id: obj
                          signal done(bool success)
                  }
                  Promise {
                          id : signalArgPromise
                          resolveWhen: obj.done(success === true)
                          rejectWhen: obj.done(success === false)
                  }
                  

                  Would it be possible to do something like this using your library?

                  B Offline
                  B Offline
                  benlau
                  Qt Champions 2016
                  wrote on 7 Mar 2018, 17:24 last edited by
                  #8

                  @cp_mark QML don't support this kind of syntax. So it should either to create signals like success / fail or check the value during the callback function:

                  onDone: {
                    if (success) {
                      signalArgPromise.resolve();
                    } else {
                      signalArgPromise.reject();
                    }
                  }
                  
                  1 Reply Last reply
                  1

                  • Login

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