Results 1 to 5 of 5

Thread: what is type?

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default what is type?

    What is the type used for in QListWidgetItem, QTreeWidgetItem, QTableWidgetItem? I see that it is used as an argument in all their constructors, with an option for UserType's, but don't know what this does or what is useful for. Seems to have something to do with rtti?

    Qt Code:
    1. QListWidgetItem(QListWidget *view = 0, int type = Type);
    To copy to clipboard, switch view to plain text mode 
    Software Engineer



  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is type?

    Yes, I think it's used for rtti. You can use this if your compiler does not support dynamic_cast or you don't want the overhead of rtti in the build*. You define a unique integer id for each subclass of QListWidgetItem that you derive, then you can use this id for comparisons when you retrieve an item in order to derive what type to cast it to.

    You can also use it to tell different items apart even when you are not using subclassing.

    * This may be important on embedded systems.
    Save yourself some pain. Learn C++ before learning Qt.

  3. The following user says thank you to Chicken Blood Machine for this useful post:

    gfunk (11th August 2006)

  4. #3
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is type?

    The Qt docs are not very elaborate about the type provided in the XXItem constructors.
    I'd say that the type identifies the data type contained in the item which gets interpreted by the related XXView classes for operations such as sorting or filtering. Since the View-Classes work mostly with QVariant types the controls need a way to figure out what
    type the data is it they have to display and process.

    Here an excerpt from the Qt doc for QVariant:

    Qt Code:
    1. QVariant::QVariant ( Type type )
    2. Constructs a null variant of type type.
    To copy to clipboard, switch view to plain text mode 

    where type is:

    Qt Code:
    1. enum QVariant::Type
    2. This enum type defines the types of variable that a QVariant can contain.
    3.  
    4. Constant Value Description
    5. QVariant::Invalid 0 no type
    6. QVariant::BitArray 13 a QBitArray
    7. QVariant::Bitmap 73 a QBitmap
    8. QVariant::Bool 1 a bool
    9.  
    10. ...
    To copy to clipboard, switch view to plain text mode 

    Regards
    Ernst

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is type?

    Quote Originally Posted by 3dch
    I'd say that the type identifies the data type contained in the item which gets interpreted by the related XXView classes for operations such as sorting or filtering.
    Unfortunately it isn't true. If it had something to do with QVariant::Type, the Trolls would use QVariant::Type instead of defining new types. Note also that QVariant object knows exactly what is the type of the value it holds and there is no need to duplicate that information. Furthermore xxxView classes use models, not xxxItems.

    Qt Code:
    1. class Q_GUI_EXPORT QListWidgetItem
    2. {
    3. friend class QListModel;
    4. public:
    5. enum { Type = 0, UserType = 1000 }; // <- note that there are only two values defined
    6. ...
    To copy to clipboard, switch view to plain text mode 

    As Chcken Blood Machine said, it's used for RTTI:
    Qt Code:
    1. : rtti(type), ... // <--
    2. ...
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Aug 2006
    Location
    Zürich, Switzerland
    Posts
    23
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is type?

    You're absolutely right. Mea culpa!

Similar Threads

  1. Replies: 3
    Last Post: 4th August 2006, 13:05
  2. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 20:11
  3. When itemChanged is emitted, can the change type be detected?
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2006, 18:29
  4. Type and User Type
    By campana in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2006, 00:22
  5. use libs under qt4
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 27th February 2006, 18:59

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.