Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean way to eliminate "unused parameter 'widget'" warning generated by QGraphicsItem::paint

Tags:

c++

qt

QGraphicsItem::paint has the following signature:

void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)

When I create custom QGraphicsItems, I have to provide an implementation for this function. The thing is... I never need to use the option and widget parameters, but I can't just remove them for obvious reasons. I always see these compiler warnings:

warning: unused parameter ‘widget’

warning: unused parameter ‘option’

Is there a proper to get rid of these warnings? I know I can hide them by mentioning the unused parameters in the function, but this is a very dirty solution and I'd like to know if there are better options.

like image 681
Pieter Avatar asked Apr 23 '11 16:04

Pieter


2 Answers

Either omit the parameter name:

void paint( ..., QWidget* ) {

or use the Q_UNUSED macro:

void paint( ..., QWidget* widget ) {
    Q_UNUSED( widget )
    ...
like image 91
Frank Osterfeld Avatar answered Sep 24 '22 18:09

Frank Osterfeld


Don't provide parameter names to the unused parameters. For example (I'm not sure what your "event" refers to), to get rid of warning: unused parameter ‘option’, change your signature to:

void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* unused */, QWidget *widget)

(The /* unused */ tag is unnecessary as far as the warning goes, but it's useful for the human reader, I find.)

like image 39
Ben Hocking Avatar answered Sep 23 '22 18:09

Ben Hocking