Let me explain it again. I intend to keep a pointer of class B in some class X. I have instantiated class B(new'ed class B) in class Y. From there i wish to pass the pointer of new'ed class B to class X. To avoid worrying about dangling pointer, instead of having B* bptr, I have QPointer<B> bptr.
Q_OBJECT
...
};
class B: public A{
Q_OBJECT
...
};
class Y{
Y(X* px){
x=px;
bptr = new B();
someMethodToAssignInX()
}
private:
void someMethodToAssignInX(){x->bptr = bptr;}
B* bptr;
X* x;
}
class X{
public:
QPointer<B> bptr;
}
class A: public QObject{
Q_OBJECT
...
};
class B: public A{
Q_OBJECT
...
};
class Y{
Y(X* px){
x=px;
bptr = new B();
someMethodToAssignInX()
}
private:
void someMethodToAssignInX(){x->bptr = bptr;}
B* bptr;
X* x;
}
class X{
public:
QPointer<B> bptr;
}
To copy to clipboard, switch view to plain text mode
Basically I want to use Qpointer to hold my pointer reference to class so that I can reap QPointer's benefits. I am not able to do so because of compilation errors.
Bookmarks