Whats does "emit operate()" mean in C++ Qt?
-
@tadamo
Simple! In C++ Qt definesemit
as empty :)#define emit
So in itself it does nothing, and your
operate()
method is called (as though you hadn't bothered insertingemit
). Which you have defined as a signal. So it raises that signal. And depending on yourconnect()
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.
-
@JonB said in Whats does "emit operate()" mean in C++ Qt?:
@tadamo
Simple! In C++ Qt definesemit
as empty :)#define emit
So in itself it does nothing, and your
operate()
method is called (as though you hadn't bothered insertingemit
). Which you have defined as a signal. So it raises that signal. And depending on yourconnect()
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 ?
-
@AnneRanch said in Whats does "emit operate()" mean in C++ Qt?:
So WHAT is the difference then ?
There is no difference in execution.
-
@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.
-
@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
-
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 theoperate()
sitting after theemit
would be called. Bit difficult to "explain" much clearer than that :)