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.
  • L Offline
    L Offline
    loladiro
    wrote on last edited by
    #4

    I'm not saying your approach is bad, but I have a few points to make:
    [quote]
    if you make mistake in method name
    [/quote]
    How is that going to be different in your approach? (Because it's done at compile time?)

    [quote]
    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. Then MOC checks if method1 can be connected to method2. And if all is OK then MOC just changes this to
    [/quote]
    There is a similar problem to the implementation suggested for Qt5. How does the MOC know which signal to use if there are multiple overloaded signals? Maybe even though the data types are the same, the information they carry is not.

    And about your example:
    @static SOCKETINFO socketz[] = {
    { "Output-1", signal class1 method1, true, Qt::AutoConnection, true },
    { "Input-1", slot class1 method2, false, Qt::AutoConnection }
    };@
    If there method 1 is overloaded how does the MOC know which method to use (the connection isn't done until later. This also holds generally. The MOC would need to check if you are within the scope of a QObject connect to perform the type matching. What if you want to write a custom method that you need to pass a signal/slot. What if you (hypothetically) override connect and it is somehow different. How is the MOC going to detect all that?

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

      bq. Oh my… This looks complicated.
      I just suggest force MOC do check job and extend new keywords as it did in class declarations. Very small additions and clear syntax…

      On the contrary, the syntax though complex is actually following the new industry standards in C++, similar syntax is used in another popular C++ library "Boost" too, and is trying to be in sync with the C++ standards committee. So as a standard, it makes it easier for coders to recognize and understand it. It also provides compile-time checking.. not to mention inlines in C++0x and many small neat things. So it's all good!

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

        Yes, and it's probably also going to improve performance (hopefully), because the compiler can make better optimizations.

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

          bq. How does the MOC know which signal to use if there are multiple overloaded signals?

          if there is more than one matching pair - it can break with error, then syntax can allow parameter type names after method name

          bq. If there method 1 is overloaded how does the MOC know which method to use

          answer is the same - error message with ability add type names

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

          if there are method1(int) and method1(int,float) then error message again - you have point type names completely to not confuse MOC

          in connection it can be done once:

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

          that means error if method2(int,float) is not declared in class2

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

            bq. So as a standard, it makes it easier for coders to recognize and understand it. It also provides compile-time checking..

            but it breaks compatibility with previous apps on the root... Will old-style connection work in Qt5?

            1 Reply Last reply
            0
            • 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

                                          • Login

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