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. Is this possible?
Forum Updated to NodeBB v4.3 + New Features

Is this possible?

Scheduled Pinned Locked Moved Unsolved General and Desktop
37 Posts 8 Posters 18.6k Views 6 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.
  • SPlattenS SPlatten

    @JonB, actually, sorry I forgot, what I actually did was add an additional signal. The control signals are connected to a slot that has matching parameters this is all in C++, that slot then creates an object that has everything in it required to identify the originating slot, finally a generic signal is emitted with the new object and its this that is connected to Lambda.

    So going back, what I really need to (if possible) dynamically create the repeater slot for each signal, which means I wouldn't have to code up and think of every possibly signal up front.

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #19

    @SPlatten said in Is this possible?:

    , which means I wouldn't have to code up and think of every possibly signal up front.

    But I think that's precisely what the discussion here is all about! C++ is statically typed, and you cannot think of every possible signal which is what you need at compile-time, and that is the issue! And I/others do not see how using lambdas would obviate that, lambdas are still subject to compile-type type checking, for both their parameters and the methods they might call....

    Perhaps we should leave it at that and you see how you get on, because we're not getting very far with a "You say, I say" ... :)

    1 Reply Last reply
    0
    • SPlattenS Offline
      SPlattenS Offline
      SPlatten
      wrote on last edited by
      #20

      @JonB , the reason for Lambda is purely to provide an interface between the C++ and the JavaScript. Using a repeater signal allows me to use the same signal out of the repeater with parameters that will never change, the receiving signal which fires the repeater is the one that will have the differences.

      Please don't get me wrong, I'm not arguing with you, I was under the impression that what I'm trying to achieve is actually possible.

      Kind Regards,
      Sy

      jsulmJ 1 Reply Last reply
      0
      • SPlattenS SPlatten

        @JonB , the reason for Lambda is purely to provide an interface between the C++ and the JavaScript. Using a repeater signal allows me to use the same signal out of the repeater with parameters that will never change, the receiving signal which fires the repeater is the one that will have the differences.

        Please don't get me wrong, I'm not arguing with you, I was under the impression that what I'm trying to achieve is actually possible.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #21

        @SPlatten Let's say you have 3 signals with different parameter lists:

        void signal1(int);
        void signal2(char*, float);
        void signal3(QString, QVariant, QString);
        

        How will you connect them to ONE slot (as you wrote: "produce a map of available signals then connect all these signals to a single slot in C++") and handle all 3 different parameter lists in that slot? Don't forget: C++ is statically typed language as already pointed out in this thread. You have different parameter number and different parameter types.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #22

          @SPlatten The way I understand your approach is this:

          cpp_signal(int)                                                                            js_slot(int)
          cpp_signal(float)                                                                          js_slot(float)
          cpp_signal(string, int)    ->  cpp_signal(common_param)   ->  cpp_slot(common_param)   ->  js_slot(string, int)
          cpp_signal(custom_class)                                                                   js_slot(custom_class_projection)
          cpp_signal(whatever)                                                                       js_slot(whatever_projection)
          

          While you can do the two transitions on the right I don't see how you can accomplish the one on the left. The target of connection takes either the same amount of the same typed parameters as the sender or less. You would have to add an extra layer of forwarding signals between the two columns on the left, but that just means a slot with every possible combination of parameters.

          Lambdas have nothing to do with any of that. A lambda, for all intents and purposes of this topic, is just a struct with () operator and follows the same static typing rules as a struct.

          That being said I really don't like to say something can't be done, so for the sake of being open minded I would imagine this could be implemented with a new type of connect that in pseudo code works like this:

          struct Param { QString name; QVariant value; }
          using ParamPack = QVector<Param>;
          
          connect(sender, &Sender::signal, func);
          

          where func is of fixed signature e.g. void (*)(const ParamPack& params) and connect is a template function that does parameter packing. This packing could in theory be done with some tuple like template shenanigans, but I suspect you'd have to use private Qt headers to get to all the stuff needed.
          To be fair, this would only work for an explicit connect statement with explicit signal so that template can take apart its signature. I don't see a way to do that by iterating over a list of signals. There's just no static type information in that case that the template could get to.

          1 Reply Last reply
          3
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by SPlatten
            #23

            @jsulm, ok if its not possible then I will have to implement my original design which is to produce a slot for each signal type and internal to that slot I will construct an object and then emit the generic signal with the constructed object which will pass on the originating signal details. This signal will be use Lambda.

            To illustrate:

            C++ signal(int)          -> Internal slot (repeater) (int)           |
            C++ signal(float)        -> Internal slot (repeater) (float)         |
            C++ signal(string, int)  -> Internal slot (repeater) (string, int)   |- Emit  
            C++ signal(custom_class) -> Internal slot (repeater) (custom_class)  |
            C++ signal(whatever)     -> Internal slot (repeater) (whatever)      |
            

            The repeaters will create a JSON object which will include details of the source signal and control associated with the signal. The Emit on the right will be a signal that will be common to all control signals and have only the constructed JSON object built by the repeater.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #24

              That's doable, but it means you will have to implement a repeater for every possible combination of any types of parameters. Unless you heavily limit possible signal signatures I don't think that's practical.

              SPlattenS S 2 Replies Last reply
              3
              • Chris KawaC Chris Kawa

                That's doable, but it means you will have to implement a repeater for every possible combination of any types of parameters. Unless you heavily limit possible signal signatures I don't think that's practical.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #25

                @Chris-Kawa , Yep, thats what I was hoping to avoid, but if its unavoidable, then I'll just have to do it and release patches / updates as I add additional controls to the engine.

                Kind Regards,
                Sy

                JonBJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @Chris-Kawa , Yep, thats what I was hoping to avoid, but if its unavoidable, then I'll just have to do it and release patches / updates as I add additional controls to the engine.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #26

                  @SPlatten said in Is this possible?:

                  then I'll just have to do it and release patches / updates as I add additional controls to the engine.

                  Originally you wrote:

                  dynamic map capable of storing the information for any QT control or derived control and it’s signals.

                  I don't mean to pour cold water/put up obstacles gratuitously for your work. But if you are going to have to release patches for each signal, what happens if I derive my own QWidgets and add my own new, dedicated signals? Which I do frequently!

                  1 Reply Last reply
                  0
                  • SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #27

                    My project is to create an engine that allows anyone to develop GUI applications for any platform that the engine is available.

                    Is it NOT intended to allow developers to modify the engine itself. It will allow anyone using the engine to develop GUI applications with XML and JavaScript.

                    Kind Regards,
                    Sy

                    JonBJ 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      My project is to create an engine that allows anyone to develop GUI applications for any platform that the engine is available.

                      Is it NOT intended to allow developers to modify the engine itself. It will allow anyone using the engine to develop GUI applications with XML and JavaScript.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #28

                      @SPlatten
                      OK, but a limitation is I cannot define any signals in my code? E.g. to go with a new widget I derive. You regard that as "modify the engine itself"?

                      1 Reply Last reply
                      0
                      • SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #29

                        That is something I will probably allow, so you can emit signals from JavaScript and connect them to slots in your own JavaScript. All signals that are available in the controls will be assessable via a subscription in XML.

                        @JonB, think about it as a developer, you want a GUI interface and there are a lot of controls available in Qt all of which you will be able to create and access using XML and JavaScript. If you want additional signals then you can create these in your JavaScript application.

                        Kind Regards,
                        Sy

                        1 Reply Last reply
                        0
                        • Chris KawaC Offline
                          Chris KawaC Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on last edited by
                          #30

                          @SPlatten Out of curiosity - how is your engine different from just using QML for example? I mean apart from the language syntax (QML vs XML). I'm asking because I rarely use these interpreted technologies (too much resource waste for my taste), but what you're describing sounds similar. Is it just that you prefer XML? There's also a QUiLoader class that can load XML based ui at runtime and you can expose that to a QJSEngine for example. Is what you're doing something more than that?

                          1 Reply Last reply
                          1
                          • SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by SPlatten
                            #31

                            @Chris-Kawa , for starters, any changes you make to QML require a rebuild of the project that references it. The entire point of my offering is that the engine is static and cannot be changed, but the XML and JavaScript can be changed and reloaded into the engine with no recompilation required.

                            Its also multi-platform, the XML and JavaScript can be ported to any Operating System where the engine is available and with no changes it will work.

                            Kind Regards,
                            Sy

                            Chris KawaC J.HilkJ 2 Replies Last reply
                            0
                            • SPlattenS SPlatten

                              @Chris-Kawa , for starters, any changes you make to QML require a rebuild of the project that references it. The entire point of my offering is that the engine is static and cannot be changed, but the XML and JavaScript can be changed and reloaded into the engine with no recompilation required.

                              Its also multi-platform, the XML and JavaScript can be ported to any Operating System where the engine is available and with no changes it will work.

                              Chris KawaC Offline
                              Chris KawaC Offline
                              Chris Kawa
                              Lifetime Qt Champion
                              wrote on last edited by
                              #32

                              @SPlatten said:

                              QML require a rebuild of the project that references it.

                              It does? I though you can just load it up from any file at runtime. Huh, I guess it just shows how little I use it :) Oh well..

                              1 Reply Last reply
                              0
                              • SPlattenS Offline
                                SPlattenS Offline
                                SPlatten
                                wrote on last edited by
                                #33

                                @Chris-Kawa , originally thats exactly how I thought QML worked too, however having worked with it now for quite a while, I scratch my head and wonder how or why it evolved in the first place into what it is....because its like everything you can do in QML you can also do in C++, granted its a little simpler but you cannot do it without rebuilding the project.

                                Kind Regards,
                                Sy

                                JonBJ 1 Reply Last reply
                                0
                                • SPlattenS SPlatten

                                  @Chris-Kawa , for starters, any changes you make to QML require a rebuild of the project that references it. The entire point of my offering is that the engine is static and cannot be changed, but the XML and JavaScript can be changed and reloaded into the engine with no recompilation required.

                                  Its also multi-platform, the XML and JavaScript can be ported to any Operating System where the engine is available and with no changes it will work.

                                  J.HilkJ Offline
                                  J.HilkJ Offline
                                  J.Hilk
                                  Moderators
                                  wrote on last edited by
                                  #34

                                  @SPlatten said in Is this possible?:

                                  QML require a rebuild of the project that references it.

                                  It most definitely does not!!
                                  I even expanded my main qml file to tricker a reload via F5 to quickly check visual changes (Sadly not a default feature)

                                  A rebuild is only needed, if you move your QML files in a resource file and load them from there, then a change requires recompiling. With local paths no recompile needed.


                                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                  Q: What's that?
                                  A: It's blue light.
                                  Q: What does it do?
                                  A: It turns blue.

                                  1 Reply Last reply
                                  3
                                  • SPlattenS SPlatten

                                    @Chris-Kawa , originally thats exactly how I thought QML worked too, however having worked with it now for quite a while, I scratch my head and wonder how or why it evolved in the first place into what it is....because its like everything you can do in QML you can also do in C++, granted its a little simpler but you cannot do it without rebuilding the project.

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #35

                                    @SPlatten , @Chris-Kawa , also now @J-Hilk
                                    Again, please don't take this as a negative comment! Bear in mind I know nothing about QML! :) But is https://doc.qt.io/qt-5/qml-qtquick-loader.html, https://qmlbook.github.io/ch14-dynamicqml/dynamicqml.html not a dynamic loader without compilation?

                                    J.HilkJ 1 Reply Last reply
                                    1
                                    • JonBJ JonB

                                      @SPlatten , @Chris-Kawa , also now @J-Hilk
                                      Again, please don't take this as a negative comment! Bear in mind I know nothing about QML! :) But is https://doc.qt.io/qt-5/qml-qtquick-loader.html, https://qmlbook.github.io/ch14-dynamicqml/dynamicqml.html not a dynamic loader without compilation?

                                      J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on last edited by J.Hilk
                                      #36

                                      @JonB same principle, you can pass a Loader either a local file url or a qrc url and it will load & evaluate at runtime


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      1 Reply Last reply
                                      4
                                      • Chris KawaC Chris Kawa

                                        That's doable, but it means you will have to implement a repeater for every possible combination of any types of parameters. Unless you heavily limit possible signal signatures I don't think that's practical.

                                        S Offline
                                        S Offline
                                        SimonSchroeder
                                        wrote on last edited by
                                        #37

                                        @Chris-Kawa said in Is this possible?:

                                        That's doable, but it means you will have to implement a repeater for every possible combination of any types of parameters. Unless you heavily limit possible signal signatures I don't think that's practical.

                                        @SPlatten I do understand where you are coming from and templates look like they should be able to do it. However, Qt does not play well with templates. Otherwise you might even be right with your approach. It would be something like templated slots. Would be really nice to have!

                                        Unfortunately, C++ is still lacking some metaprogramming capabilities. In order to avoid too much code duplication for each possible combination of types in your signals' signatures I would in fact suggest using macros. You might want to have a quick look at so called X macros. Basically you would then #define a list of signatures for your slots and then let a macro implement all the slots for this list. I would consider this use of macros cleaner than implementing the same over and over again. "Implementing" a new signature is then as easy as adding it to the list. Only disadvantage of this might be when you try to debug it (you cannot step through a multiline macro...).

                                        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