c++qtmacros

Supressing "unused parameter" warning inside of code


I want to supress an unsued parameter warning within the code.

My first approach was:

void RenderGraphFrame::mouseReleaseEvent(QMouseEvent *UNUSED(event))
{
    MousebuttonHold = false;
    updateGL();
    return;
}

where the definitions are as followed:

#define UNUSED(NAME) USE_IT(NAME)
#define USE_IT(NAME) UNUSED_ ## NAME

This didn't work. After a bit of SO research I figgured out that in C++ I simply could do:

void RenderGraphFrame::mouseReleaseEvent(QMouseEvent)
{/*...*/}

Well this fixed the problem with the warning perfectly, but now.... the mouseReleaseEvent() Isn't triggered anymore at all. So this also isn't working for me.

So what other ways I do have for supressing the warning with a in code variant?


Solution

  • This is because the parameter of QWidget::mouseReleaseEvent is a pointer. You must keep the *:

    void RenderGraphFrame::mouseReleaseEvent(QMouseEvent*)
    {
      // Your code
    }