diff -crB qt-everywhere-opensource-src-4.6.3.orig/src/corelib/tools/qsharedpointer.cpp qt-everywhere-opensource-src-4.6.3/src/corelib/tools/qsharedpointer.cpp
*** qt-everywhere-opensource-src-4.6.3.orig/src/corelib/tools/qsharedpointer.cpp	2010-06-02 04:03:17.000000000 +0200
--- qt-everywhere-opensource-src-4.6.3/src/corelib/tools/qsharedpointer.cpp	2010-08-13 12:16:00.000000000 +0200
***************
*** 1239,1272 ****
      QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
  
      if (d->sharedRefcount)
!         qFatal("QSharedPointer: pointer %p already has reference counting", obj);
      d->sharedRefcount = this;
  
      // QObject decreases the refcount too, so increase it up
      weakref.ref();
  }
  
! QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::getAndRef(const QObject *obj)
  {
      Q_ASSERT(obj);
-     QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
-     Q_ASSERT_X(!d->wasDeleted, "QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted");
  
!     ExternalRefCountData *that = d->sharedRefcount;
!     if (that) {
!         that->weakref.ref();
!         return that;
      }
  
      // we can create the refcount data because it doesn't exist
!     ExternalRefCountData *x = new ExternalRefCountData(Qt::Uninitialized);
      x->strongref = -1;
      x->weakref = 2;  // the QWeakPointer that called us plus the QObject itself
!     if (!d->sharedRefcount.testAndSetRelease(0, x)) {
          delete x;
!         d->sharedRefcount->weakref.ref();
      }
!     return d->sharedRefcount;
  }
  
  QT_END_NAMESPACE
--- 1239,1295 ----
      QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
  
      if (d->sharedRefcount)
!         qFatal("QSharedPointer: QObject %p already has reference counting", obj);
      d->sharedRefcount = this;
  
      // QObject decreases the refcount too, so increase it up
      weakref.ref();
  }
  
! void QtSharedPointer::ExternalRefCountData::setQObjectShared(const QSharedFromThis * obj, bool enable)
  {
      Q_ASSERT(obj);
  
!     if (obj->sharedRefcount)
!         qFatal("QSharedPointer: QSharedFromThis %p already has reference counting", obj);
!     const_cast<QSharedFromThis *>(obj)->sharedRefcount = this;
! 
!     // QObject decreases the refcount too, so increase it up
!     weakref.ref();
! }
! 
! static QtSharedPointer::ExternalRefCountData *sharedRefcountGetAndRef(QAtomicPointer<QtSharedPointer::ExternalRefCountData> &sharedRefCount)
! {
!     if (sharedRefCount) {
!     	sharedRefCount->weakref.ref();
!         return sharedRefCount;
      }
  
      // we can create the refcount data because it doesn't exist
!     QtSharedPointer::ExternalRefCountData *x = new QtSharedPointer::ExternalRefCountData(Qt::Uninitialized);
      x->strongref = -1;
      x->weakref = 2;  // the QWeakPointer that called us plus the QObject itself
!     if (!sharedRefCount.testAndSetRelease(0, x)) {
          delete x;
!         sharedRefCount->weakref.ref();
      }
!     return sharedRefCount;
! }
! 
! QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::getAndRef(const QObject *obj)
! {
!     Q_ASSERT(obj);
!     QObjectPrivate *d = QObjectPrivate::get(const_cast<QObject *>(obj));
!     Q_ASSERT_X(!d->wasDeleted, "QWeakPointer", "Detected QWeakPointer creation in a QObject being deleted");
! 
!     return sharedRefcountGetAndRef(d->sharedRefcount);
! }
! 
! QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::getAndRef(const QSharedFromThis *obj)
! {
!     Q_ASSERT(obj);
! 
!     return sharedRefcountGetAndRef(const_cast<QSharedFromThis *>(obj)->sharedRefcount);
  }
  
  QT_END_NAMESPACE
***************
*** 1500,1505 ****
--- 1523,1543 ----
  #  endif
  }
  
+ QSharedFromThis::~QSharedFromThis()
+ {
+     if (sharedRefcount) {
+         if (sharedRefcount->strongref > 0) {
+             qWarning("QSharedFromThis: shared QSharedFromThis was deleted directly. The program is malformed and may crash.");
+             // but continue deleting, it's too late to stop anyway
+         }
+ 
+         // indicate to all QWeakPointers that this QSharedFromThis has now been deleted
+         sharedRefcount->strongref = 0;
+         if (!sharedRefcount->weakref.deref())
+             delete sharedRefcount;
+     }
+ }
+ 
  QT_END_NAMESPACE
  
  #endif
diff -crB qt-everywhere-opensource-src-4.6.3.orig/src/corelib/tools/qsharedpointer_impl.h qt-everywhere-opensource-src-4.6.3/src/corelib/tools/qsharedpointer_impl.h
*** qt-everywhere-opensource-src-4.6.3.orig/src/corelib/tools/qsharedpointer_impl.h	2010-06-02 04:03:17.000000000 +0200
--- qt-everywhere-opensource-src-4.6.3/src/corelib/tools/qsharedpointer_impl.h	2010-08-13 12:16:00.000000000 +0200
***************
*** 77,82 ****
--- 77,83 ----
  //
  template <class T> class QWeakPointer;
  template <class T> class QSharedPointer;
+ class QSharedFromThis;
  
  template <class X, class T>
  QSharedPointer<X> qSharedPointerCast(const QSharedPointer<T> &ptr);
***************
*** 192,197 ****
--- 193,200 ----
          Q_CORE_EXPORT static ExternalRefCountData *getAndRef(const QObject *);
          Q_CORE_EXPORT void setQObjectShared(const QObject *, bool enable);
  #endif
+         Q_CORE_EXPORT static ExternalRefCountData *getAndRef(const QSharedFromThis *);
+         Q_CORE_EXPORT void setQObjectShared(const QSharedFromThis *, bool enable);
          inline void setQObjectShared(...) { }
      };
      // sizeof(ExternalRefCount) = 12 (32-bit) / 16 (64-bit)
***************
*** 653,658 ****
--- 656,683 ----
      T *value;
  };
  
+ class QSharedFromThis
+ {
+ protected:
+ 	QSharedFromThis()
+ 	{}
+ 	QSharedFromThis(const QSharedFromThis&)
+ 	{}
+ 	QSharedFromThis& operator=(QSharedFromThis&)
+ 	{ return *this; }
+ 	Q_CORE_EXPORT ~QSharedFromThis();
+ private:
+ 	friend class QtSharedPointer::ExternalRefCountData;
+ 	QAtomicPointer<QtSharedPointer::ExternalRefCountData> sharedRefcount;
+ };
+ 
+ 
+ template <class T>
+ QSharedPointer<T> QSharedFrom(T* ptr)
+ {
+ 	return QSharedPointer<T>(QWeakPointer<T>(ptr));
+ }
+ 
  template <class T, class X>
  bool operator==(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
  {
