PDA

View Full Version : QPaintEvent syntax question



last2kn0
25th January 2008, 18:10
I just have a simple question about the syntax of writing a paintEvent handler.
Specifically, I have seen in many places when writing the event handler, the event pointer is commented out in the parameter list like this:


Class::paintEvent(QPaintEvent * /* event */)

Why is this done? I have compiled it with and without the comments and it has performed the same way. I haven't found any explanation for this.

Thanks !

jpn
25th January 2008, 18:39
The result of

void Class::paintEvent(QPaintEvent* /* event */)
{
...
}

and

void Class::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
}

is the same; the compiler won't complain about an unused parameter. Although the latter is more readable, isn't it? :)

last2kn0
25th January 2008, 18:42
Yeahhh, thats what I was thinking it was about. I didn't get any compiler complaints so it just made me wonder. Thanks a lot for the quick reply. Sometimes those little things that I don't know just bother me!

:) Thanks again

wysota
25th January 2008, 19:02
I don't think it is more readable. It's just another convention. And the first version will compile faster :P

jpn
25th January 2008, 19:35
I don't think it is more readable. It's just another convention. And the first version will compile faster :P
Maybe not for you, but just imagine the difference when someone not so familiar with C++ ends up maintaining that application. ;)

wysota
25th January 2008, 20:36
As long as you don't remove the parameter name and just surround it with a comment, the readability shouldn't suffer much. But of course everybody has his/her own ways. I tend to use Q_UNUSED myself too.