Results 1 to 6 of 6

Thread: QPaintEvent syntax question

  1. #1
    Join Date
    Oct 2007
    Location
    USA
    Posts
    27
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QPaintEvent syntax question

    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:

    Qt Code:
    1. Class::paintEvent(QPaintEvent * /* event */)
    To copy to clipboard, switch view to plain text mode 

    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 !

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPaintEvent syntax question

    The result of
    Qt Code:
    1. void Class::paintEvent(QPaintEvent* /* event */)
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. void Class::paintEvent(QPaintEvent* event)
    2. {
    3. Q_UNUSED(event);
    4. }
    To copy to clipboard, switch view to plain text mode 
    is the same; the compiler won't complain about an unused parameter. Although the latter is more readable, isn't it?
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Location
    USA
    Posts
    27
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPaintEvent syntax question

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPaintEvent syntax question

    I don't think it is more readable. It's just another convention. And the first version will compile faster :P

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPaintEvent syntax question

    Quote Originally Posted by wysota View Post
    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.
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPaintEvent syntax question

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.