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. Are lambda signals and slots handled by moc
Forum Updated to NodeBB v4.3 + New Features

Are lambda signals and slots handled by moc

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 447 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.
  • T Offline
    T Offline
    Tahar
    wrote on last edited by Tahar
    #1

    I asked GPT3, and it said NO, with this as an example

    GPT:

    QObject::connect(sender, &Sender::signalName, this, [](int value) {
        qDebug() << "Lambda slot called with value:" << value;
    });
    

    In this example, the lambda function is used as a slot directly with the QObject::connect syntax. The connection is made using the pointer-to-member-function syntax (&Sender::signalName) instead of using the old-style SIGNAL and SLOT macros

    In summary, lambda functions used as signals and slots in Qt are not handled by the MOC. They provide a modern and efficient way of connecting signals and slots in your application without the need for MOC-generated code.

    Christian EhrlicherC 1 Reply Last reply
    0
    • T Tahar

      I asked GPT3, and it said NO, with this as an example

      GPT:

      QObject::connect(sender, &Sender::signalName, this, [](int value) {
          qDebug() << "Lambda slot called with value:" << value;
      });
      

      In this example, the lambda function is used as a slot directly with the QObject::connect syntax. The connection is made using the pointer-to-member-function syntax (&Sender::signalName) instead of using the old-style SIGNAL and SLOT macros

      In summary, lambda functions used as signals and slots in Qt are not handled by the MOC. They provide a modern and efficient way of connecting signals and slots in your application without the need for MOC-generated code.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Moc is only needed for old-styled connect(), introspection and qml integration.

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

      T 1 Reply Last reply
      1
      • T Tahar has marked this topic as solved on
      • Christian EhrlicherC Christian Ehrlicher

        Moc is only needed for old-styled connect(), introspection and qml integration.

        T Offline
        T Offline
        Tahar
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Thanks for the response, is there a source where I can read more about this?

        Christian EhrlicherC 1 Reply Last reply
        0
        • T Tahar

          @Christian-Ehrlicher
          Thanks for the response, is there a source where I can read more about this?

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Maybe https://doc.qt.io/qt-6/moc.html , https://doc.qt.io/qt-6/why-moc.html and https://doc.qt.io/qt-6/metaobjects.html

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

          JonBJ 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            Maybe https://doc.qt.io/qt-6/moc.html , https://doc.qt.io/qt-6/why-moc.html and https://doc.qt.io/qt-6/metaobjects.html

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

            @Christian-Ehrlicher
            Is moc required to qobject_cast<> to your Q_OBJECT classes?

            And it says there it's required for tr() which affects many coders.

            Christian EhrlicherC 1 Reply Last reply
            0
            • JonBJ JonB

              @Christian-Ehrlicher
              Is moc required to qobject_cast<> to your Q_OBJECT classes?

              And it says there it's required for tr() which affects many coders.

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB said in Are lambda signals and slots handled by moc:

              Is moc required to qobject_cast<> to your Q_OBJECT classes?

              Yes since qobject_cast<> is using stuff generated by moc (the metaobject name)

              And it says there it's required for tr() which affects many coders.

              This would be new to me.
              lupdate fetches the strings by parsing the source code, not some moc stuff. The context comes from the class name. You could take a look into the generated moc file to see if there is something wrt translation.

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

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @JonB said in Are lambda signals and slots handled by moc:

                Is moc required to qobject_cast<> to your Q_OBJECT classes?

                Yes since qobject_cast<> is using stuff generated by moc (the metaobject name)

                And it says there it's required for tr() which affects many coders.

                This would be new to me.
                lupdate fetches the strings by parsing the source code, not some moc stuff. The context comes from the class name. You could take a look into the generated moc file to see if there is something wrt translation.

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

                @Christian-Ehrlicher
                Your https://doc.qt.io/qt-6/metaobjects.html listed:

                In addition to providing the signals and slots mechanism for communication between objects (the main reason for introducing the system), the meta-object code provides the following additional features:

                • QObject::tr() translates strings for internationalization.
                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