Proper way to check QObject derived class type in Qt

后端 未结 1 545
余生分开走
余生分开走 2021-02-13 03:53

Lets say I have a two classes:

class A : public QObject {};
class B : public QObject {};

then I go

QObject *a = new A();
QObje         


        
1条回答
  •  孤城傲影
    2021-02-13 04:26

    You can use qobject_cast(instance) on QObject derived classes and check the return value. If instance cannot be cast to MyClass*, the return value will be NULL.

    0 讨论(0)
提交回复
热议问题