[Qt-interest] 答复: 答复: how to know derive class

pengliang(彭亮) pengliang at founder.com
Fri Nov 12 01:36:58 CET 2010


Hi Andre:
       Yes, your answer is my want.
       Thank you.

Thanks
彭亮 Ken
-----邮件原件-----
发件人: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] 代表 Andre Somers
发送时间: 2010年11月11日 20:51
收件人: qt-interest at trolltech.com
主题: Re: [Qt-interest] 答复: how to know derive class

Op 11-11-2010 12:00, Konrad Rosenbaum schreef:
> On Thursday 11 November 2010 09:00:52 pengliang(彭亮) wrote:
>> Thank you.
>> But how to know which QWidget is QLineEdit and which is QComboBox?
>> Is this only method?
> Well, let's spell it out for you:
>
> if(qobject_cast<QLineEdit*>(myobject)!=0)
>   qDebug("It's a Line Edit!");
> else
> if(qobject_cast<QComboBox*>(myobject)!=0)
>   qDebug("It's a Combo!");
> else
>  qDebug("Ooops, it's something else!");
>
> Now please read the docu of qobject_cast... ;-)
>
Of course. But also read up on QObject::inherits()

if (myObject.inherits("QLineEdit") {
foo();
}

André
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list