[Qt-interest] No RTTI information for QTreeWidgetItem

Eric Clark eclark at ara.com
Tue Jun 2 18:52:32 CEST 2009


I know what you mean. I have done that with derived classes before, that is probably a good idea to fix my concern. Well... as long as everyone follows the rules. :) I work on a framework, like Qt, but it is a 3D modeling and simulation framework. Sometimes I get concerned with developers using our framework not following the rules. But, that is their problem, right.

Thank you for all your help, I really do appreciate it Scott!

Eric

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Tuesday, June 02, 2009 11:44 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

Gotcha...  I don't think its any different then with custom model roles.

In my derived class, I usually create a public enum and create a new "add to this number and you are safe" enumeration

Scott

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Eric Clark
Sent: Tuesday, June 02, 2009 9:39 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

No. I do not mind doing this, actually it is probably faster than a dynamic cast, but I am a little concerned that there is no way to "reserve" the type number like there is with custom Event types. With Events, you can register your event number, but I do not see the ability to do this with QTreeWidgetItem's types. Is there a way that you know of? I am just concerned about the same number being reused with someone else's derived type.

Eric

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Tuesday, June 02, 2009 11:28 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

Its really no different.. is it any different doing 5-10 (depending on how many QTreeWidgetItem derived classes) if ( item->type() ) vs 5-10 castes?

Scott

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Eric Clark
Sent: Tuesday, June 02, 2009 6:47 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

I had a feeling that was the only solution. Thank you very much!

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Monday, June 01, 2009 5:27 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

No it wont.. I missed that...

Instead do the following, make sure you set your Type during the construction, and call QTreeWidgetItem::type() to figure out what type of type it is

Scott



From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Eric Clark
Sent: Monday, June 01, 2009 2:08 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] No RTTI information for QTreeWidgetItem

Scott,

Thank you for the response, but I would not have a problem using qobject_cast, except that QTreeWidgetItem does not inherit QObject. Will qobject_cast work on non-QObjects?

Eric

From: Scott Aron Bloom [mailto:Scott.Bloom at sabgroup.com]
Sent: Monday, June 01, 2009 4:04 PM
To: Eric Clark; qt-interest at trolltech.com
Subject: RE: [Qt-interest] No RTTI information for QTreeWidgetItem

Don't use RTTI on QT based objects... (in fact its rather unsafe when crossing any DLL boundry on windows...) use qobject_cast

Scott

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Eric Clark
Sent: Monday, June 01, 2009 1:05 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] No RTTI information for QTreeWidgetItem

Hello All,

I have a class that inherits QTreeWidgetItem. When I attempt to do a dynamic_cast on a QTreeWidgetItem that was created using my subclass BaseTreeWidgetItem I get an exception thrown by Microsoft C++ that says the object is a __non_rtti_object. Has anyone seen this problem? If I just cast the object instead of using a dynamic_cast everything works just fine.

Thanks in advance!
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090602/8f00e7d2/attachment.html 


More information about the Qt-interest-old mailing list