Results 1 to 4 of 4

Thread: Regarding Qt's documentation on operators and related non-members

  1. #1
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Regarding Qt's documentation on operators and related non-members

    Two (maybe five) questions have been bugging at me:
    1. Why doesn't the Qt documentation contain copy constructors and assignment operators for certain "value-based" classes like QDate, QTime, QChar and QPoint? How come QDateTime does? Should I avoid writing "QDate newDate = otherDate"?

    2. What are "Related non-members" and where do they belong, if not in the classes they're documented under?

  2. #2
    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: Regarding Qt's documentation on operators and related non-members

    Quote Originally Posted by hackerNovitiate View Post
    1. Why doesn't the Qt documentation contain copy constructors and assignment operators for certain "value-based" classes like QDate, QTime, QChar and QPoint? How come QDateTime does? Should I avoid writing "QDate newDate = otherDate"?
    Every class has those (regardless if they are hand written or provided by the compiler) so why document that and clutter the view? Same goes with destructors.

    2. What are "Related non-members" and where do they belong, if not in the classes they're documented under?
    They are exactly that - entities (like functions or macros) that are not members of the class but semantically belong to the class (e.g. qHash() implementations for QHash class).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Regarding Qt's documentation on operators and related non-members

    Quote Originally Posted by hackerNovitiate View Post
    Two (maybe five) questions have been bugging at me:
    1. Why doesn't the Qt documentation contain copy constructors and assignment operators for certain "value-based" classes like QDate, QTime, QChar and QPoint? How come QDateTime does? Should I avoid writing "QDate newDate = otherDate"?
    The copy operator is implicit. QDate for example has only one data member: uint jd; i.e. julian date as an unsigned int. It's faster (and easier) to copy that than to (im|ex)plicitly share the thing.

    Quote Originally Posted by hackerNovitiate View Post
    2. What are "Related non-members" and where do they belong, if not in the classes they're documented under?
    They could theoretically also be related to something else. In case of QString:
    Qt Code:
    1. bool operator!= ( const char * s1, const QString & s2 )
    2. const QString operator+ ( const QString & s1, const QString & s2 )
    3. const QString operator+ ( const QString & s1, const char * s2 )
    4. const QString operator+ ( const char * s1, const QString & s2 )
    5. const QString operator+ ( char ch, const QString & s )
    6. const QString operator+ ( const QString & s, char ch )
    7. bool operator< ( const char * s1, const QString & s2 )
    8. QDataStream & operator<< ( QDataStream & stream, const QString & string )
    9. bool operator<= ( const char * s1, const QString & s2 )
    10. bool operator== ( const char * s1, const QString & s2 )
    11. bool operator> ( const char * s1, const QString & s2 )
    12. bool operator>= ( const char * s1, const QString & s2 )
    13. QDataStream & operator>> ( QDataStream & stream, QString & string )
    To copy to clipboard, switch view to plain text mode 
    Some of these operators would be impossible to create when defining them as member (operator!=(const char *, QString) for example).
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  4. #4
    Join Date
    Jan 2010
    Location
    Perth, Australia
    Posts
    37
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Regarding Qt's documentation on operators and related non-members

    Thanks guys; after your explanations and some digging around the Qt source code, things make a lot more sense.

    Every class has those (regardless if they are hand written or provided by the compiler) so why document that and clutter the view? Same goes with destructors.
    Some classes had them documented whilst others didn't; I got confused by this. I thought that if a function isn't documented, it must be either unavailable, or not meant for public use. I didn't realize the documentation also reflects the implementation.

    Now to the next level: I'm very curious as to why QPoint (which has 2 ints as data members) uses a non-member comparator while QLine (which has 2 QPoints as data members) uses a member comparator?

    Qt Code:
    1. // For QPoint (a friend function)
    2. inline bool operator==(const QPoint &p1, const QPoint &p2)
    3. { return p1.xp == p2.xp && p1.yp == p2.yp; }
    4.  
    5. // For QLine (a member function)
    6. inline bool QLine::operator==(const QLine &d) const
    7. { return pt1 == d.pt1 && pt2 == d.pt2; }
    To copy to clipboard, switch view to plain text mode 

    Unlike franz's QString example, I'd imagine things would still work if they were both members (or both non-members), right? Does the current implementation provide any particular benefits?

Similar Threads

  1. for i = 0 to nr members in a class ...
    By qt_gotcha in forum Qt Programming
    Replies: 4
    Last Post: 6th March 2010, 19:38
  2. QDataStream class/struct & stream operators
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2008, 19:40
  3. pointer to members
    By mickey in forum General Programming
    Replies: 2
    Last Post: 31st December 2007, 17:50
  4. Adding Qt's documentation to Xcode documentation browser
    By fabietto in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2007, 15:38
  5. Do assignment operators in Qt4 return deep or shallow copy?
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 09:01

Tags for this Thread

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.