[Qt-interest] 答复: how to know derive class
Andre Somers
andre at familiesomers.nl
Thu Nov 11 13:51:23 CET 2010
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é
More information about the Qt-interest-old
mailing list