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. Whats does "emit operate()" mean in C++ Qt?
Qt 6.11 is out! See what's new in the release blog

Whats does "emit operate()" mean in C++ Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 6 Posters 14.2k 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
    tadamo
    wrote on last edited by
    #1

    Hello,

    What exactly does the following instruction:

    emit operate();
    

    mean in C ++ Qt?

    Thanks.

    JonBJ 1 Reply Last reply
    0
    • T tadamo

      Hello,

      What exactly does the following instruction:

      emit operate();
      

      mean in C ++ Qt?

      Thanks.

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

      @tadamo
      Simple! In C++ Qt defines emit as empty :)

      #define emit
      

      So in itself it does nothing, and your operate() method is called (as though you hadn't bothered inserting emit). Which you have defined as a signal. So it raises that signal. And depending on your connect()s, that will cause your slots to be called, either immediately (default) or when Qt next hits the event loop.

      Using emit is just a "nicety", to show it's a signal function being called. Gives you something to search the code for.

      If you have not done so yet, you must read https://doc.qt.io/qt-5/signalsandslots.html, you will need to understand signals & slots for Qt programming.

      A 1 Reply Last reply
      8
      • JonBJ JonB

        @tadamo
        Simple! In C++ Qt defines emit as empty :)

        #define emit
        

        So in itself it does nothing, and your operate() method is called (as though you hadn't bothered inserting emit). Which you have defined as a signal. So it raises that signal. And depending on your connect()s, that will cause your slots to be called, either immediately (default) or when Qt next hits the event loop.

        Using emit is just a "nicety", to show it's a signal function being called. Gives you something to search the code for.

        If you have not done so yet, you must read https://doc.qt.io/qt-5/signalsandslots.html, you will need to understand signals & slots for Qt programming.

        A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @JonB said in Whats does "emit operate()" mean in C++ Qt?:

        @tadamo
        Simple! In C++ Qt defines emit as empty :)

        #define emit
        

        So in itself it does nothing, and your operate() method is called (as though you hadn't bothered inserting emit). Which you have defined as a signal. So it raises that signal. And depending on your connect()s, that will cause your slots to be called, either immediately (default) or when Qt next hits the event loop.

        Using emit is just a "nicety", to show it's a signal function being called. Gives you something to search the code for.

        If you have not done so yet, you must read https://doc.qt.io/qt-5/signalsandslots.html, you will need to understand signals & slots for Qt programming.

        Please clarify / verify

        if operate() is defined as SIGNAL

        emit operate(); emits signal / function operate

        operate((); runs signal / function operate

        So WHAT is the difference then ?

        jsulmJ KroMignonK 2 Replies Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AnneRanch said in Whats does "emit operate()" mean in C++ Qt?:

          So WHAT is the difference then ?

          There is no difference in execution.

          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
          4
          • A Anonymous_Banned275

            @JonB said in Whats does "emit operate()" mean in C++ Qt?:

            @tadamo
            Simple! In C++ Qt defines emit as empty :)

            #define emit
            

            So in itself it does nothing, and your operate() method is called (as though you hadn't bothered inserting emit). Which you have defined as a signal. So it raises that signal. And depending on your connect()s, that will cause your slots to be called, either immediately (default) or when Qt next hits the event loop.

            Using emit is just a "nicety", to show it's a signal function being called. Gives you something to search the code for.

            If you have not done so yet, you must read https://doc.qt.io/qt-5/signalsandslots.html, you will need to understand signals & slots for Qt programming.

            Please clarify / verify

            if operate() is defined as SIGNAL

            emit operate(); emits signal / function operate

            operate((); runs signal / function operate

            So WHAT is the difference then ?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @AnneRanch said in Whats does "emit operate()" mean in C++ Qt?:

            So WHAT is the difference then ?

            There is NO difference. emit is an empty macro, it is only used to make it clear that a signal is emitted. So

            emit operate();
            

            simply calls operate() method, doesn't matter whether it is declared as signal or not. If it is declared as signal, then the generated (see moc tool) implementation in operate() is executed and connected slots are called.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            5
            • A Anonymous_Banned275

              @JonB said in Whats does "emit operate()" mean in C++ Qt?:

              @tadamo
              Simple! In C++ Qt defines emit as empty :)

              #define emit
              

              So in itself it does nothing, and your operate() method is called (as though you hadn't bothered inserting emit). Which you have defined as a signal. So it raises that signal. And depending on your connect()s, that will cause your slots to be called, either immediately (default) or when Qt next hits the event loop.

              Using emit is just a "nicety", to show it's a signal function being called. Gives you something to search the code for.

              If you have not done so yet, you must read https://doc.qt.io/qt-5/signalsandslots.html, you will need to understand signals & slots for Qt programming.

              Please clarify / verify

              if operate() is defined as SIGNAL

              emit operate(); emits signal / function operate

              operate((); runs signal / function operate

              So WHAT is the difference then ?

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #6

              @AnneRanch said in Whats does "emit operate()" mean in C++ Qt?:

              So WHAT is the difference then ?

              Please take time to read response!

              As @JonB told you, emit has no meaning, you can remove it without trouble. This is only a "syntactic sugar" to help you on code reading to known that you are using a signal.

              Signals/slots are very important in Qt, you have to know how they work to be able to right develop with Qt.
              Take time to read documentation:

              • basics : https://doc.qt.io/qt-5/signalsandslots.html
              • more details: https://woboq.com/blog/how-qt-signals-slots-work.html

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              1 Reply Last reply
              4
              • JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                I said what it meant, I showed the macro definition to be empty, I explained emit expands to nothing and is only there to allow you to search for something [or the vain hope years ago that the C++ language would change ;-) ], and said the operate() sitting after the emit would be called. Bit difficult to "explain" much clearer than that :)

                1 Reply Last reply
                6

                • Login

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