Results 1 to 4 of 4

Thread: Regarding syntax

  1. #1
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Regarding syntax

    Hi!!

    I haven't yet undrstood the syntax of inheritance in QT.

    For example, the directory browser example code says->

    1. class FileItem : public QListViewItem
    2. {
    3. public:
    4. FileItem( QListViewItem *parent, const QString &s1, const QString &s2 )
    5. : QListViewItem( parent, s1, s2 ), pix( 0 ) {}
    6.
    7. const QPixmap *pixmap( int i ) const;
    8. void setPixmap( QPixmap *p );
    9.
    10. private:
    11. QPixmap *pix;
    12.
    13. };

    the lines 4 and 5, does the construtor of class FileItem inherit the constructor of class QListViewItem??. the syntax is confusing.. I think the constructors are overloaded. Or is it the way of overloading. Please guide me as i am unable to understand what lines 4 & 5 mean.

  2. #2
    Join Date
    Aug 2009
    Location
    Greece, Chania
    Posts
    63
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Regarding syntax

    This is a C++ issue about constructors that every basic C++ book covers this topic.
    When you call the constructor of FileItem, it will call the constructor inherited from QListViewItem passing the given arguments. Also you got the constructor for QPixmap initializing it to 0. This is what those lines are doing.
    Misha R.evolution - High level Debugging IDE

    Programming is about 2 basic principles: KISS and RTFM!!!

  3. The following user says thank you to Archimedes for this useful post:

    Yayati.Ekbote (27th January 2010)

  4. #3
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: Regarding syntax

    Hi,

    the lines 4 and 5, does the construtor of class FileItem inherit the constructor of class QListViewItem??
    Clearly you have to review ur c++ basics here.


    the syntax is confusing.. I think the constructors are overloaded. Or is it the way of overloading.
    In c++, constructors can be overloaded.
    Ex.
    Qt Code:
    1. class TEST_CLASS_FOR_YOU
    2. {
    3. TEST_CLASS_FOR_YOU();
    4. TEST_CLASS_FOR_YOU(int a);
    5. TEST_CLASS_FOR_YOU(int a,int b);
    6. }
    To copy to clipboard, switch view to plain text mode 

    for furthur please refer this link http://www.cplusplus.com/doc/tutorial/



    No going back the example.

    4. FileItem( QListViewItem *parent, const QString &s1, const QString &s2 )
    5. : QListViewItem( parent, s1, s2 ), pix( 0 ) {}
    This is defination of constructor FileItem which is derived from QListViewItem class. QListViewItem class has overloaded constructor QListViewItem( parent, s1, s2 ) which is called at initillization. this is not a defination of QListViewItem( parent, s1, s2 ) class remember.

  5. The following user says thank you to vishwajeet.dusane for this useful post:

    Yayati.Ekbote (27th January 2010)

  6. #4
    Join Date
    Jan 2010
    Posts
    37
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Regarding syntax

    thanks for the reply.
    Last edited by Yayati.Ekbote; 27th January 2010 at 14:20.

Similar Threads

  1. QListWidget syntax highlight
    By Ken_Afford in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 15:54
  2. Need help getting QAbstractItemView syntax correct
    By Hookem in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2008, 09:34
  3. Odd Syntax
    By acxdotfm in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2008, 20:23
  4. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 10:09
  5. QPaintEvent syntax question
    By last2kn0 in forum Newbie
    Replies: 5
    Last Post: 25th January 2008, 20:36

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.