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. MOC: signals and slots can't be on same line
Forum Updated to NodeBB v4.3 + New Features

MOC: signals and slots can't be on same line

Scheduled Pinned Locked Moved Unsolved General and Desktop
mocqt5.15.2linker errors
17 Posts 4 Posters 2.1k Views 2 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.
  • C Christian Ehrlicher
    8 Jul 2021, 16:40

    Feel free to provide a patch to moc for your usecase :)

    M Offline
    M Offline
    mattfbacon
    wrote on 8 Jul 2021, 16:41 last edited by
    #3

    @Christian-Ehrlicher The issue I have is in regards to what specifically MOC is struggling with. moc -E shows the correct output.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mattfbacon
      wrote on 8 Jul 2021, 16:53 last edited by
      #4

      If I can get confirmation that this is intended behavior, I will just revert to using 2 macros. I just want to make sure this isn't a bug.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 8 Jul 2021, 17:40 last edited by
        #5

        As it does not work it's not implemented in moc so it's a not intended use case. If you want this feature provide a patch, maybe it gets integrated.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        M 1 Reply Last reply 8 Jul 2021, 19:59
        0
        • V Offline
          V Offline
          VRonin
          wrote on 8 Jul 2021, 18:17 last edited by
          #6

          did you try the inline versions?

          #define SIGNAL_SLOT(NAME, ...) \
            Q_SLOT void update_ ## NAME(__VA_ARGS__); \
            Q_SIGNAL void NAME ## _changed(__VA_ARGS__)
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          M 1 Reply Last reply 8 Jul 2021, 21:42
          1
          • C Christian Ehrlicher
            8 Jul 2021, 17:40

            As it does not work it's not implemented in moc so it's a not intended use case. If you want this feature provide a patch, maybe it gets integrated.

            M Offline
            M Offline
            mattfbacon
            wrote on 8 Jul 2021, 19:59 last edited by
            #7

            @Christian-Ehrlicher doesn't work != not implemented. As I said before I want to make sure it's not a bug. The same code written out without macros works fine, and the macros are all expanded correctly according to moc -E.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 8 Jul 2021, 20:42 last edited by
              #8

              Please show a header which does not work, without any macros so we can see what you really want and what not work.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              M 1 Reply Last reply 8 Jul 2021, 21:54
              0
              • V VRonin
                8 Jul 2021, 18:17

                did you try the inline versions?

                #define SIGNAL_SLOT(NAME, ...) \
                  Q_SLOT void update_ ## NAME(__VA_ARGS__); \
                  Q_SIGNAL void NAME ## _changed(__VA_ARGS__)
                
                M Offline
                M Offline
                mattfbacon
                wrote on 8 Jul 2021, 21:42 last edited by
                #9

                @VRonin Yes this works!! Thank you for addressing the problem 😌 I guess I am still a bit of a Qt newbie, since I've never heard of those inline annotations, but they are super useful for macros like these!

                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  8 Jul 2021, 20:42

                  Please show a header which does not work, without any macros so we can see what you really want and what not work.

                  M Offline
                  M Offline
                  mattfbacon
                  wrote on 8 Jul 2021, 21:54 last edited by mattfbacon 7 Aug 2021, 21:59
                  #10

                  @Christian-Ehrlicher I believe I have found the underlying issue:

                  Expanding the macros to exactly their output:

                  class Foo : public QObject {
                    Q_OBJECT
                  // ...
                  public slots: void update_property(bool); signals: void property_changed(bool);
                  protected:
                    bool property;
                  };
                  

                  does not compile either (same linker errors with the signals). You can't have slots and signals on the same line. However, C++ is meant to be a whitespace-insensitive language, so I still think this is a bug in MOC, albeit a different one. I will change the title.

                  J 1 Reply Last reply 9 Jul 2021, 05:35
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 9 Jul 2021, 04:54 last edited by
                    #11

                    Even it's a 'bug' in moc it will unlikely to be changed, and when then not before 6.3 so ... don't see why this is needed though.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    M 1 Reply Last reply 9 Jul 2021, 23:50
                    0
                    • M mattfbacon
                      8 Jul 2021, 21:54

                      @Christian-Ehrlicher I believe I have found the underlying issue:

                      Expanding the macros to exactly their output:

                      class Foo : public QObject {
                        Q_OBJECT
                      // ...
                      public slots: void update_property(bool); signals: void property_changed(bool);
                      protected:
                        bool property;
                      };
                      

                      does not compile either (same linker errors with the signals). You can't have slots and signals on the same line. However, C++ is meant to be a whitespace-insensitive language, so I still think this is a bug in MOC, albeit a different one. I will change the title.

                      J Offline
                      J Offline
                      JKSH
                      Moderators
                      wrote on 9 Jul 2021, 05:35 last edited by
                      #12

                      @mattfbacon said in MOC: signals and slots can't be on same line:

                      C++ is meant to be a whitespace-insensitive language, so I still think this is a bug in MOC

                      Yes, C++ is meant to be whitespace-insensitive. However, moc currently parses files using a custom text processor, not a full-fledged C++ engine. The processor currently doesn't support having "signals:" and "slots:" on the same line.

                      If you're interested, here's an experiment that reimplements moc on top of libclang, which gives it more capabilities in understanding arbitrary C++: https://woboq.com/blog/moc-with-clang.html

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      M 1 Reply Last reply 9 Jul 2021, 22:08
                      3
                      • J JKSH
                        9 Jul 2021, 05:35

                        @mattfbacon said in MOC: signals and slots can't be on same line:

                        C++ is meant to be a whitespace-insensitive language, so I still think this is a bug in MOC

                        Yes, C++ is meant to be whitespace-insensitive. However, moc currently parses files using a custom text processor, not a full-fledged C++ engine. The processor currently doesn't support having "signals:" and "slots:" on the same line.

                        If you're interested, here's an experiment that reimplements moc on top of libclang, which gives it more capabilities in understanding arbitrary C++: https://woboq.com/blog/moc-with-clang.html

                        M Offline
                        M Offline
                        mattfbacon
                        wrote on 9 Jul 2021, 22:08 last edited by
                        #13

                        @JKSH Interesting. Looks like moc-ng is fully functional; I will have to try that on my project.

                        M 1 Reply Last reply 9 Jul 2021, 22:47
                        0
                        • M mattfbacon
                          9 Jul 2021, 22:08

                          @JKSH Interesting. Looks like moc-ng is fully functional; I will have to try that on my project.

                          M Offline
                          M Offline
                          mattfbacon
                          wrote on 9 Jul 2021, 22:47 last edited by
                          #14

                          @JKSH Scratch that, just realized that the project is almost two years old and won't compile. Really, moc should be using a full C++ parser...

                          J C 2 Replies Last reply 10 Jul 2021, 05:13
                          0
                          • C Christian Ehrlicher
                            9 Jul 2021, 04:54

                            Even it's a 'bug' in moc it will unlikely to be changed, and when then not before 6.3 so ... don't see why this is needed though.

                            M Offline
                            M Offline
                            mattfbacon
                            wrote on 9 Jul 2021, 23:50 last edited by
                            #15

                            @Christian-Ehrlicher It's not strictly needed but without it the signals: and slots: section labels don't work like others. This makes signals and slots a leaky abstraction. This is especially true when you consider that Qt 5 moc is supposed to support macros, but macros can't have newlines so they are forced to put it all on the same line. In this context, unless you want to mark everything inline with Q_SLOT and Q_SIGNAL (and $DEITY forbid your macro actually wants to change the context for code after it), you're out of luck.

                            1 Reply Last reply
                            0
                            • M mattfbacon
                              9 Jul 2021, 22:47

                              @JKSH Scratch that, just realized that the project is almost two years old and won't compile. Really, moc should be using a full C++ parser...

                              J Offline
                              J Offline
                              JKSH
                              Moderators
                              wrote on 10 Jul 2021, 05:13 last edited by
                              #16

                              @mattfbacon said in MOC: signals and slots can't be on same line:

                              Really, moc should be using a full C++ parser...

                              I agree, that would be ideal.

                              However, something like libclang did not exist when moc was invented. To reimplement it now with libclang is a costly and risky exercise. Can you show that the benefits outweigh the risks?

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              1 Reply Last reply
                              0
                              • M mattfbacon
                                9 Jul 2021, 22:47

                                @JKSH Scratch that, just realized that the project is almost two years old and won't compile. Really, moc should be using a full C++ parser...

                                C Offline
                                C Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on 10 Jul 2021, 08:22 last edited by
                                #17

                                @mattfbacon said in MOC: signals and slots can't be on same line:

                                Really, moc should be using a full C++ parser...

                                Again: feel free to provide a patch instead blaming around that a corner case does not work...

                                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                Visit the Qt Academy at https://academy.qt.io/catalog

                                1 Reply Last reply
                                0

                                12/17

                                9 Jul 2021, 05:35

                                • Login

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