Quote Originally Posted by steg90 View Post
wysota - class looks cool
Thx It probably doesn't work, but still thx

A bit more about QPointer - the whole magic in QPointer is that it connects to the destroyed() signal emitted from every QObject when it gets deleted, so it's easy to synchronize all pointers and it's safe to use it when regular pointers point to the same object. The minimal implementation of QPointer is:

Qt Code:
  1. class MyPointer : public QObject {
  2. Q_OBJECT
  3. public:
  4. MyPointer(QObject *object, QObject *parent=0){
  5. m_ptr = object;
  6. if(m_ptr)
  7. connect(m_ptr, SIGNAL(destroyed()), SLOT(_q_destroyed()));
  8. }
  9. // stuff returning and operating on the pointer goes here, like:
  10. operator T * () const{ return m_ptr; }
  11. private slots:
  12. void _q_destroyed(){
  13. m_ptr =0;
  14. }
  15. private:
  16. QObject *m_ptr;
  17. }
To copy to clipboard, switch view to plain text mode