Qt-interest Archive, December 2006
qobject_cast for Qt3
Message 1 in thread
Hi Guys,
Just thought like making a qobject_cast for Qt3.
This is an intial draft, so please give your suggestions
So here goes the qobject_cast
#include <qmetaobject.h>
template < typename T >
inline T qobject_cast( QObject *object ){
T dummy;
if( object->inherits( dummy->staticMetaObject()->className()) ){
return static_cast< T >( object );
}
return 0;
}
So does this help in anyway ?
--
[ signature omitted ]
Message 2 in thread
"Sunil Thaha" <sunil.thaha@xxxxxxxxx> wrote in message
news:31cda5180612180514u5995931dq1f6c6a733b91b28e@xxxxxxxxxxxxxxxxx
> Hi Guys,
>
> Just thought like making a qobject_cast for Qt3.
> This is an intial draft, so please give your suggestions
>
> So here goes the qobject_cast
>
> #include <qmetaobject.h>
>
> template < typename T >
> inline T qobject_cast( QObject *object ){
> T dummy;
> if( object->inherits( dummy->staticMetaObject()->className()) ){
> return static_cast< T >( object );
> }
> return 0;
> }
>
> So does this help in anyway ?
See ::qt_cast in Qt 3 (in qobjectdefs.h, calling qt_inheritedBy in
qobject.cpp).
Note that comparing meta-object pointers performed by both qobject_cast
and ::qt_cast is significantely faster than string comparison, and safer
(the class "MainWidget" coming from some 3rd party DLL might be a very
different class from the "MainWidget" class in your application that you
want to cast to).
Volker
--
[ signature omitted ]
Message 3 in thread
In the interests of public mental health*, I'd like to report that if you want to construct a QKeySequence from a QString for the Page Up or Page Down buttons (in Qt3, at least) you need to use "PgUp" or "PgDown", not, as you might expect, "PageUp" or "PageDown".
Cheers
Sam Dutton
*just went a bit crazy trying to debug this...
SAM DUTTON
SENIOR SITE DEVELOPER
200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK
Please Note:
Any views or opinions are solely those of the author and do not necessarily represent
those of Independent Television News Limited unless specifically stated.
This email and any files attached are confidential and intended solely for the use of the individual
or entity to which they are addressed.
If you have received this email in error, please notify postmaster@xxxxxxxxx
Please note that to ensure regulatory compliance and for the protection of our clients and business,
we may monitor and read messages sent to and from our systems.
Thank You.


Message 4 in thread
Hi,
> In the interests of public mental health*, I'd like to report that if
> you want to construct a QKeySequence from a QString for the Page Up or
> Page Down buttons (in Qt3, at least) you need to use "PgUp" or "PgDown",
> not, as you might expect, "PageUp" or "PageDown".
Indeed this does not seem to be documented. Worse, the QKeySequence
refers to key codes listed in qnamespace.h:
Key_Prior = 0x1016, Key_PageUp = Key_Prior,
Key_Next = 0x1017, Key_PageDown = Key_Next,
while the source code in qkeysequence.cpp mysteriously reads:
{ Qt::Key_PageUp, QT_TRANSLATE_NOOP("QShortcut", "PgUp") },
{ Qt::Key_PageDown, QT_TRANSLATE_NOOP("QShortcut", "PgDown") },
It should be either PgUp or PageUp, but not a mix of both. In any case
this should probably be documented some way or the other.
--
[ signature omitted ]