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. Writing QML Application in a Flux way
Forum Updated to NodeBB v4.3 + New Features

Writing QML Application in a Flux way

Scheduled Pinned Locked Moved QML and Qt Quick
fluxdesign pattern
33 Posts 10 Posters 20.6k Views 5 Watching
  • 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.
  • V Offline
    V Offline
    Vincent007
    wrote on 24 Dec 2015, 11:37 last edited by
    #12

    Hi Ben,

    Thank for your contributions!

    Did you discuss about writing QML Application in a Flux way with developers of Qt via Qt development mailing list?

    If not, why not?

    Merry Christmas!

    B 1 Reply Last reply 24 Dec 2015, 14:06
    0
    • V Vincent007
      24 Dec 2015, 11:37

      Hi Ben,

      Thank for your contributions!

      Did you discuss about writing QML Application in a Flux way with developers of Qt via Qt development mailing list?

      If not, why not?

      Merry Christmas!

      B Offline
      B Offline
      benlau
      Qt Champions 2016
      wrote on 24 Dec 2015, 14:06 last edited by
      #13

      @Vincent007 no. hmmm... Just I can't think of any reason to send to dev mailing list. Ask them for comment? or ask them to include related class in next version? Ofcoz it will be better if more people can comment / raise suggestion, but I just not sure should I send to dev mailing list.

      Merry Christmas!

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vincent007
        wrote on 24 Dec 2015, 14:42 last edited by Vincent007
        #14

        Hi Ben,

        I think your work can help Qt developers think how QML should be evolved in feature. Therefore you can discuss with them about the evolution of QML by your work.

        B 1 Reply Last reply 28 Dec 2015, 05:17
        0
        • V Vincent007
          24 Dec 2015, 14:42

          Hi Ben,

          I think your work can help Qt developers think how QML should be evolved in feature. Therefore you can discuss with them about the evolution of QML by your work.

          B Offline
          B Offline
          benlau
          Qt Champions 2016
          wrote on 28 Dec 2015, 05:17 last edited by
          #15

          @Vincent007 hmm. Let's me think about it. By the way, I am going to publish another article with similar topic but better explanation, code and diagram on a blog in this week.

          B 1 Reply Last reply 2 Jan 2016, 21:26
          0
          • C Offline
            C Offline
            clogwog
            wrote on 2 Jan 2016, 15:01 last edited by
            #16

            Hi Ben,

            i'm not sure if this is a bug but i'm trying to figure out how to use quickflux by making a small change to the todo example.

            I added a 'mark all items done' button and mark all items as done. however the ui doesn't always update.

            example: 1) start application (3 items in list 1 in done)
            2) press 'all done' -> all items disappear (expected)
            3) show all items by checking 'show completed' (expecteD)
            4) unmark one item (for example 'Task A')
            5) press 'all done' -> 'Task A' doesn't update to done ?

            if i uncheck and re-check 'show completed' the model and view are back in sync.

            https://github.com/clogwog/fluxtest1

            am i missing something ?

            B 1 Reply Last reply 2 Jan 2016, 17:27
            0
            • C clogwog
              2 Jan 2016, 15:01

              Hi Ben,

              i'm not sure if this is a bug but i'm trying to figure out how to use quickflux by making a small change to the todo example.

              I added a 'mark all items done' button and mark all items as done. however the ui doesn't always update.

              example: 1) start application (3 items in list 1 in done)
              2) press 'all done' -> all items disappear (expected)
              3) show all items by checking 'show completed' (expecteD)
              4) unmark one item (for example 'Task A')
              5) press 'all done' -> 'Task A' doesn't update to done ?

              if i uncheck and re-check 'show completed' the model and view are back in sync.

              https://github.com/clogwog/fluxtest1

              am i missing something ?

              B Offline
              B Offline
              benlau
              Qt Champions 2016
              wrote on 2 Jan 2016, 17:27 last edited by
              #17

              @clogwog I can't reproduce your problem in my example program and in your code. When it is set to "Show Completed". It will show every tasks. So if you set a task done in "Show Completed" mode. It won't disappear. The behaviour should be correct.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                clogwog
                wrote on 2 Jan 2016, 21:14 last edited by clogwog 1 Mar 2016, 00:22
                #18

                no, i was expecting it to show all tasks as you said, i just expected it to switch back to checked when i pressed the 'all done' button

                so when you are in the 'show completed' mode in step 5 with a task you just set to 'uncompleted' and then press 'all done' your tasks goes back to checked ?

                B 1 Reply Last reply 3 Jan 2016, 07:47
                0
                • B benlau
                  28 Dec 2015, 05:17

                  @Vincent007 hmm. Let's me think about it. By the way, I am going to publish another article with similar topic but better explanation, code and diagram on a blog in this week.

                  B Offline
                  B Offline
                  benevo
                  wrote on 2 Jan 2016, 21:26 last edited by
                  #19

                  @benlau

                  Hi Ben,

                  Thank for your sparking idea about this area, It's charming & meaningful to do this.
                  BTW, could U show the link of Ur another article with better description if possible.

                  Thanks !

                  Happy New Year !

                  1 Reply Last reply
                  0
                  • C clogwog
                    2 Jan 2016, 21:14

                    no, i was expecting it to show all tasks as you said, i just expected it to switch back to checked when i pressed the 'all done' button

                    so when you are in the 'show completed' mode in step 5 with a task you just set to 'uncompleted' and then press 'all done' your tasks goes back to checked ?

                    B Offline
                    B Offline
                    benlau
                    Qt Champions 2016
                    wrote on 3 Jan 2016, 07:47 last edited by
                    #20

                    @clogwog said:

                    no, i was expecting it to show all tasks as you said, i just expected it to switch back to checked when i pressed the 'all done' button

                    so when you are in the 'show completed' mode in step 5 with a task you just set to 'uncompleted' and then press 'all done' your tasks goes back to checked ?

                    oh, you mean in your program. I didn't realize that you have added a "All Done" button. The problem is about data binding in Qt. Qt use one-way data binding. Although it has binded CheckBox.checked to model.done , the binding will lost whatever it is toggled by user event. It is overridden by system. And that is why step 5 failed.

                    You may solve this problem in this way:

                    At TodoVisualDataModel.qml:

                        delegate: TodoItem {
                            id:item
                            uid: model.uid
                            title: model.title
                            property bool done: model.done
                    
                            onDoneChanged: {
                                checked = model.done;
                            }
                    
                            Component.onCompleted: {
                                item.VisualDataModel.inNonCompleted = Qt.binding(function() { return !model.done})
                            }
                        }
                    

                    @benevo: thx. The article is not ready yet. I will post it within this few days.

                    1 Reply Last reply
                    1
                    • C Offline
                      C Offline
                      clogwog
                      wrote on 3 Jan 2016, 20:15 last edited by
                      #21

                      @benlau thank you for taking the time to tell me this !
                      i have learned something new.

                      kind regards,
                      tom

                      1 Reply Last reply
                      0
                      • stackprogramerS Offline
                        stackprogramerS Offline
                        stackprogramer
                        wrote on 4 Jan 2016, 07:18 last edited by
                        #22

                        nice,thanks for share,i think MVC is too good for our Qml project.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          benlau
                          Qt Champions 2016
                          wrote on 4 Jan 2016, 19:41 last edited by
                          #23

                          @benevo @Vincent007 The new article is ready.

                          Action-Dispatcher Design Pattern for QML — Medium

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            Vincent007
                            wrote on 6 Jan 2016, 03:16 last edited by
                            #24

                            @benlau

                            Do you think it is beneficial to use Action-Dispatcher Design Pattern in C++ ?
                            If Yes, would you mind giving us an example in C++ ?

                            B 1 Reply Last reply 6 Jan 2016, 18:12
                            0
                            • V Vincent007
                              6 Jan 2016, 03:16

                              @benlau

                              Do you think it is beneficial to use Action-Dispatcher Design Pattern in C++ ?
                              If Yes, would you mind giving us an example in C++ ?

                              B Offline
                              B Offline
                              benlau
                              Qt Champions 2016
                              wrote on 6 Jan 2016, 18:12 last edited by
                              #25

                              @Vincent007 yes, I think so. However, I am not coding in pure C++ way. I could provide a C++ and QML mixing example code. Before it is ready, you may take a look about the C++ API of QuickFlux:

                              QFAppDispatcher Class | QuickFlux 1.0

                              V 1 Reply Last reply 11 Jan 2016, 15:47
                              0
                              • B benlau
                                6 Jan 2016, 18:12

                                @Vincent007 yes, I think so. However, I am not coding in pure C++ way. I could provide a C++ and QML mixing example code. Before it is ready, you may take a look about the C++ API of QuickFlux:

                                QFAppDispatcher Class | QuickFlux 1.0

                                V Offline
                                V Offline
                                Vincent007
                                wrote on 11 Jan 2016, 15:47 last edited by
                                #26

                                @benlau Thank for your new example in advance!

                                I think it is time to show your work to Qt contributors via Qt development mailing list. I think your work can help Qt contributors think how QML should be evolved in feature.

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  Vincent007
                                  wrote on 22 Feb 2016, 13:40 last edited by
                                  #27

                                  Someone implemented FLUX too!

                                  B 1 Reply Last reply 24 Feb 2016, 06:35
                                  0
                                  • V Vincent007
                                    22 Feb 2016, 13:40

                                    Someone implemented FLUX too!

                                    B Offline
                                    B Offline
                                    benlau
                                    Qt Champions 2016
                                    wrote on 24 Feb 2016, 06:35 last edited by
                                    #28

                                    @Vincent007 Interesting. thx.

                                    I am happy to see more people talking about using Flux in Qt/QML even they are not using my library. That means the approach really works. Moreover, until now, I don't see a standard QML application guide available yet. I would like to draw more attention from Qt users / developers to think about this problem.

                                    p.s I have added a FAQ about why it need a Dispatcher instead of just a QObject:

                                    Why use AppDispatcher instead of listening from AppActions directly?

                                    1 Reply Last reply
                                    0
                                    • B Offline
                                      B Offline
                                      benlau
                                      Qt Champions 2016
                                      wrote on 26 Feb 2016, 04:23 last edited by
                                      #29

                                      v1.0.4 has been released.

                                      New Components

                                      KeyTable

                                      KeyTable is an object with properties equal to its key name. Once it's construction is completed, it will search all of its string property. If it is a string type and not assigned to any value, it will set its value by its name. It can be used to create ActionTypes.qml in QuickFlux Application.

                                      Example:

                                      KeyTable {
                                      
                                          // It will be set to "customField1" in Component.onCompleted callback.
                                          property string customField1;
                                      
                                          // Since it is already assigned a value, KeyTable will not modify this property.
                                          property string customField2 : "value";
                                      
                                      }
                                      

                                      Filter

                                      Filter component listens for the parent's dispatched signal, if a dispatched signal match with its type, it will emit its own "dispatched" signal. Otherwise, it will simply ignore the signal.

                                      This component provides an alternative way to filter incoming message which is suitable for making Store component.

                                      Example:

                                      pragma Singleton
                                      import QtQuick 2.0
                                      import QuickFlux 1.0
                                      import "../actions"
                                      
                                      AppListener {
                                          id: store
                                      
                                          property ListModel model: ListModel { }
                                      
                                          Filter {
                                              type: ActionTypes.addTask
                                              onDispatched: {
                                                  model.append({task: message.task});
                                              }
                                          }
                                      
                                      }
                                      

                                      It is not suggested to use nested AppListener in a Store component. Because nested AppListener do not share the same AppListener::listenerId, it will be difficult to control the order of message reception between store component.

                                      In contrast, Filter share the same listenerId with its parent, and therefore it is a solution for above problem.

                                      Changes

                                      AppScript

                                      1. Added "autoExit" property

                                      examples/todo

                                      1. Migrated to use KeyTable and Filter
                                      2. Added StoreAdapter to demonstrate how to use "waitFor" between stores.

                                      StoreAdapter.qml

                                      import QtQuick 2.0
                                      import "../stores"
                                      
                                      Item {
                                      
                                          Component.onCompleted: {
                                              TodoStore.waitFor = [UserPrefsStore.listenerId];
                                          }
                                      
                                      }
                                      
                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        benlau
                                        Qt Champions 2016
                                        wrote on 21 Mar 2016, 05:57 last edited by
                                        #30

                                        QuickFlux v1.0.5 has been released.

                                        New Component

                                        ActionCreator

                                        ActionCreator is a component that listens on its own signals, convert to message then dispatch via AppDispatcher. The message type will be same as the signal name. There has no limitation on number of arguments and data type.

                                        For example, you may declare an ActionCreator based component as:

                                        import QtQuick 2.0
                                        import QuickFlux 1.0
                                        pragma singleton
                                        
                                        ActionCreator {
                                          signal open(string url);
                                        }
                                        

                                        It is equivalent to:

                                        import QtQuick 2.0
                                        import QuickFlux 1.0
                                        pragma singleton
                                        
                                        Item {
                                           function open(url) {
                                             AppDispatcher.dispatch(“open”, {url: url});
                                           }
                                        }
                                        

                                        Changes

                                        QFAppDispatcher

                                        1. Added dispatch(const QString &type, const QVariant& message) member method for C++ to dispatch message.
                                        1 Reply Last reply
                                        0
                                        • B Offline
                                          B Offline
                                          benlau
                                          Qt Champions 2016
                                          wrote on 21 Feb 2017, 02:22 last edited by
                                          #31

                                          v1.0.6 has been released

                                          New Component

                                          1. Object - It is a QtObject that able to hold children component.

                                          Changes

                                          1. Filter

                                          a) Now it could listen from any component that has "dispatched" signal

                                          Item {
                                            signal dispatched(string type, var message)
                                          
                                            Filter {
                                              type: ActionTypes.addItem
                                              onDispatched: {}
                                            }
                                          }
                                          
                                          

                                          b) Support to hold children item

                                          Filter {
                                            Promise {
                                            }
                                          }
                                          

                                          c) Added "types" property to filter multiple types of action

                                          Filter {
                                            types: [ActionTypes.addItem , ActionTypes.removeItem]
                                          }
                                          

                                          2. ActionCreator

                                          a) Added "genKeyTable()"

                                          According to the registered signal in the ActionCreator object, it could create a key table (ActionTypes) in QML.

                                          3. KeyTable

                                          a) Added getSourceFile()/genHeaderFile() - Generate a C++ header and source file for this KeyTable object.

                                          Bug Fix:

                                          1. [QTBUG-58133] Crash on emitting a signal from C++ to QML with undefined QJSValue - Qt Bug Tracker

                                          2. qmlRegisterType under MSVC goes nuts · Issue #7 · benlau/quickflux

                                          Preview of Quick Flux 1.1

                                          As a preview of new components in v1.1, they are also included in this release. But the API is not frozen. It may change in the official release.

                                          1. Dispatcher - non-singleton Dispatcher
                                          2. MiddlewareList / Middleware - a mechanism to extend the functionality of dispatcher allowing for advanced asynchronous workflow and integration with visual component like FileDialo
                                          3. Store - A replacement of AppListener
                                          4. Hydrate - Serialize and deserialize a store to/from a JSON object.
                                          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