Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. What about little help with signals and slots checking?
QtWS25 Last Chance

What about little help with signals and slots checking?

Scheduled Pinned Locked Moved Qt Creator and other tools
28 Posts 8 Posters 11.6k 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.
  • G Offline
    G Offline
    Gourmand
    wrote on last edited by
    #9

    If you are seriously aware about "syntax standard" - it can be:

    @static SOCKETINFO socketz[] = {
    { "Output-1", signal class1::method1( int, true ), Qt::AutoConnection, true },
    { "Input-1", slot class1 method2, false, Qt::AutoConnection }
    };@
    and

    @connect( signal (class1)this::method1( int, float ), slot (class2) other::method2 );@

    but the idea assumes it is compatible to already created applications

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #10

      The new syntax is supposed to be an addition to the existing one. At least that is what was said at QtCS.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gourmand
        wrote on last edited by
        #11

        That's good. That means my suggestion does not intersect with new syntax. They can exist both. MOC additions should be made only by MOC developer(s) and only in MOC. It could appear for Qt4 and be further used in Qt5. Programmer will choose what is better for him.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #12

          I wonder what a C++ compiler does with your syntax. To me it looks like it will consider the connect statement a syntax error and bail out. The compiler needs to parse the code as well as moc.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gourmand
            wrote on last edited by
            #13

            bq. I wonder what a C++ compiler does with your syntax.

            The C++ compiler must not see that! After MOC it should be the conventional C++ syntax with present SIGNAL() and SLOT() macros!

            @static SOCKETINFO socketz[] = {
            { "Output-1", signal class1::method1( int, true ), Qt::AutoConnection, true },
            { "Input-1", slot class1::method2, false, Qt::AutoConnection }
            };@
            MOC shout turn to
            @static SOCKETINFO socketz[] = {
            { "Output-1", SIGNAL(measuredValue( float )), true, Qt::AutoConnection, true },
            { "Input-1", SLOT(activateMeasure( int )), false, Qt::AutoConnection }
            };@

            and
            @connect( signal (class1)this::method1( int, float ), slot (class2)other::method2 );@
            to
            @connect( (class1)this, SIGNAL(method1( int, float )), (class2)other, SLOT(method2( int, float )) );@
            but if only matching method2( int, float ) declared in class2

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #14

              The MOC cannot modify your files.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #15

                The point is, MOC does create source code and is no pre processor for the c++ compiler. so C++ compiler would see

                @
                connect( signal (class1)this::method1( int, float ), slot (class2)other::method2 );
                @

                which can't be simply mapped with #defines.

                @
                connect( this, SIGNAL(method1( int, float )), other, SLOT(method2( int, float )) );
                @

                will be expanded by the pre processor to

                @
                QObject::connect(this, "1method1( int, float )", other, "2method2( int, float )");
                @

                Using this method, you can event connect QObject pointers without knowing the real implementation class. With your syntax it is mandatory to know them inside the class doing the connect, which means connect on QObject pointer is only possible for QObject slots/signals.

                On the other side, the new sysntax is not complex, it's just C++ standard (pointer to member) and STL. This is nice, as this is also standard.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Gourmand
                  wrote on last edited by
                  #16

                  But MOC could work like preprocessor.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    loladiro
                    wrote on last edited by
                    #17

                    Well yes, but as Gerolf pointed out, the MOC is not preprocessor, so the compiler will till see your syntax in the cpp file.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #18

                      No, MOC can't work as pre provcessor. This would mean to modify the build chain, as pre processor creates an intermediate file used by the processor. If moc should work as pre processor, it must create the first intermediate file, which is then processed by the pre processor of the used build chain, which also means to modify the make file syntax to something, noone will understand.

                      It makes no sense from my POV.

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        Gourmand
                        wrote on last edited by
                        #19

                        Hm... are there still any people who looks at automatically generated makefiles?... :-D

                        BTW I still did not get - will new Qt5 syntax and checking work for statically initialized pointers to signals/slots?

                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          Franzk
                          wrote on last edited by
                          #20

                          [quote author="Gourmand" date="1308685686"]Hm... are there still any people who looks at automatically generated makefiles?... :-D[/quote]
                          That would be me.

                          The thing that really worries me about the new syntax is the fact that encapsulation is broken. That isn't all that good from my point of view. Signals and slots traditionally helped in decoupling and encapsulation. It would be a shame to throw that away to support a new syntax that only has local advantages. I do like the non-blocking open file example, but if it means breaking a lot of goodness, I rather write a slot or two instead.

                          Overloading of slots is probably going to be discouraged according to the doc, which is rather useless if you want to keep the "normal class function with added calling possibilities".

                          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #21

                            If I understood correctly, old and new syntax should work, so that would mean, old stuff will go on working, and decoupling also.

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0
                            • F Offline
                              F Offline
                              Franzk
                              wrote on last edited by
                              #22

                              [quote author="Gerolf" date="1308722120"]If I understood correctly, old and new syntax should work, so that would mean, old stuff will go on working, and decoupling also.[/quote]
                              True that. The encapsulation is achieved by keeping the signals protected, which has to be changed for the new syntax to work. To be honest, that still sounds like a deal-breaker to me.

                              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                              http://www.catb.org/~esr/faqs/smart-questions.html

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                jim_kaiser
                                wrote on last edited by
                                #23

                                I agree with Franzk on the worry about breaking encapsulation (especially the example about having a public aboutToQuit signal which can then called/emitted from another class!). But i'm positive, they will find a solution for that.

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #24

                                  Encapsulation is already broken with signals and slots. I don't see how making the signals public will break it more than it already is. Even now, you can use this to trigger a signal in another object:

                                  @
                                  QMetaObject::invokeMethod(theOtherObject, "myDangerousSignal", Q_ARG(bool, m_selfDestruct));
                                  @

                                  Making the signal public will make the above a bit easier, but the effect won't be any different:
                                  @
                                  theOtherObject->myDangerousSignal(m_selfDestruct);
                                  @

                                  Same goes for slots, by the way. They are open to the public if a user really wants to, even the ones you declared as private.

                                  Bottom line for me: there needs to be careful consideration if making the signals public is worth the benefit. Making them public may send the wrong message in terms of API design, but the actual protection of the methods does not change. That makes it, in my eyes, not a deal-braker if the benefits are great enough.

                                  1 Reply Last reply
                                  0
                                  • J Offline
                                    J Offline
                                    jim_kaiser
                                    wrote on last edited by
                                    #25

                                    I agree too it's not a deal breaker.. but it is a concern that needs to be addressed. While using the

                                    @ QMetaObject::invokeMethod(myObject, mySignal) @

                                    It is a level of abstraction and it's clear when we want to script the object and make it emit some signal. The normal legal way being the

                                    @ emit mySignal(); @

                                    Which of course cannot be done by classes other than the owner.

                                    But bringing that to the level of a C++ method call is breaking encapsulation.. the goal being to prevent such dangerous access to the class.

                                    1 Reply Last reply
                                    0
                                    • F Offline
                                      F Offline
                                      Franzk
                                      wrote on last edited by
                                      #26

                                      There is a big difference between having to type
                                      @QMetaObject::invokeMethod(theOtherObject, "myDangerousSignal", Q_ARG(bool, m_selfDestruct));@
                                      and just being able to type
                                      @theOtherObject->myDangerousSignal(m_selfDestruct);@
                                      and get away with it because the signal is considered public by the compiler

                                      Edit: Improved sentence.

                                      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • D Offline
                                        D Offline
                                        dangelog
                                        wrote on last edited by
                                        #27

                                        I think the thread went a bit off topic when dealing with Qt5 overloads for connect() accepting lambdas, pointer to members etc.

                                        bq. Why MOC cannot do that check?

                                        What you suggest is doable, but moc IMHO is the wrong place to do that. Instead, you should move the logic into the compiler itself, and have it check at compile time (whenever it's possible) that the specified signals and slots in the connect() statement DO exist in the respective classes. For instance, you could write a gcc plugin (in Python) to do exactly that, and emit a warning in case the compiler finds something strange with a connect.

                                        Notice also that any Qt-enabled IDE (YMMV) will help you in writing the right connect statements, and refactoring the relevant code.

                                        bq. Then MOC when meets these extensions – it just performs checking of existence method1 in class1 and it’s definition as signal. Same for slot method2 in class2. Notice that parameters of methods are omited – MOC can take them from declarations of these methods. For example they are both int.

                                        What's exactly the advantage of doing that? And by the way, it's generally wrong. You can have overloads for both signals and slots, therefore more than one match can possibly exist.

                                        Software Engineer
                                        KDAB (UK) Ltd., a KDAB Group company

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          Gourmand
                                          wrote on last edited by
                                          #28

                                          bq. Instead, you should move the logic into the compiler itself

                                          no, in my idea checking must perform before preprocessing to change additional keywords to fine-tuned SIGNAL and SLOT macros

                                          if only it was built into preprocessor before it's main engine...

                                          bq. You can have overloads for both signals and slots, therefore more than one match can possibly exist.

                                          you just did not read forward, later I told about overloading - if this appears and processor confuses, then it just prints out an error - and extra parameters declaration solves problem

                                          but this all is not interesting for people here, including authors... this could be interesting only for developers who want use old connection style and have check at compile time

                                          bq. Notice also that any Qt-enabled IDE (YMMV) will help you

                                          thanx but I've already got accustomed to QtCreator

                                          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