I dont understand the benefits of use it.
Can anybody explain it ?
Thanks
I dont understand the benefits of use it.
Can anybody explain it ?
Thanks
As the docs say:
Q_UNUSED ( name )
Indicates to the compiler that the parameter with the specified name is not used in the body of a function. This can be used to suppress compiler warnings while allowing functions to be defined with meaningful parameter names in their signatures.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I already read the docs.
I dont understand what means :
Thanks.... with the specified name is not used in the body of a function ...
If you have a method which takes two variables and you don't use one of them, then one of them is unused, yes? So you can use Q_UNUSED macro to tell the compiler that you didn't forget about it and you know it's unused, otherwise you could receive warning message.
Qt Code:
int foo::bar(int a1, int a2, int a3) { Q_UNUSED(a3); int r = a1 + a2; return r; }To copy to clipboard, switch view to plain text mode
Ok, I understand !!!
( And I have delete what I had written.)
Thanks
But i can't understand WHY to pass unusued parameter?
You might get unused parameters when you implement a slot to match a signal, or implement a virtual function, but do not need everything that is passed in order to complete your processing. For example, you might want to know when the "textChanged(QString)" signal is emitted from a QLineEdit but not care what the text changed to:
Qt Code:
{ Q_UNUSED(text); // make obnoxious noise }To copy to clipboard, switch view to plain text mode
You can also suppress the warnings like this:
Qt Code:
{ // make obnoxious noise }To copy to clipboard, switch view to plain text mode
for example :
Qt Code:
{ Q_UNUSED(parent); list.removeAt(index.row()); return true; }To copy to clipboard, switch view to plain text mode
The parent parameter is not used inside the body of the function, which could result in a warning. Q_UNUSED here helps avoiding this warning, explicitly telling the compiler you're not using the concerned parameter.
I didn't really check in the Qt sources, but I guess the Q_UNUSED macro is defined like this :
Qt Code:
#define Q_UNUSED(arg) (void)arg;To copy to clipboard, switch view to plain text mode
Bookmarks