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

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 1 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.
  • L Offline
    L Offline
    loladiro
    wrote on 21 Jun 2011, 19:34 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 21 Jun 2011, 19:40 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 21 Jun 2011, 19:48 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 21 Jun 2011, 20:12 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 22 Jun 2011, 05:55 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 22 Jun 2011, 06:04 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 22 Jun 2011, 08:20 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 22 Jun 2011, 10:56 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 22 Jun 2011, 11:16 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 22 Jun 2011, 11:29 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 22 Jun 2011, 12:45 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 22 Jun 2011, 17:19 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

                          26/28

                          22 Jun 2011, 11:29

                          • Login

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