これができない理由がわかりません。次の例を見てください。
class Parent : public QObject
{
public:
virtual void AbstractMethod() = 0;
};
class Child: public Parent
{
public:
virtual void AbstractMethod() { }
QString PrintMessage() { return "This is really the Child Class"; }
};
次のように QPointer を初期化します。
QPointer<Parent> pointer = new Child();
その後、QPointer で通常行うように、「抽象」クラスでメソッドを呼び出すことができます
pointer->AbstractMethod();
親クラスで定義された抽象メソッドを使用して必要なものすべてにアクセスできるため、理想的にはこれで十分です。
ただし、子クラスを区別する必要がある場合や、子クラスにのみ存在するものを使用する必要がある場合は、dynamic_cast を使用できます。
Child *_ChildInstance = dynamic_cast<Child *>(pointer.data());
// If _ChildInstance is NULL then pointer does not contain a Child
// but something else that inherits from Parent
if (_ChildInstance != NULL)
{
// Call stuff in your child class
_ChildInstance->PrintMessage();
}
それが役立つことを願っています。
追加の注意: QPointer に実際に何かが含まれていることを確認するために、pointer.isNull() もチェックする必要があります。