Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.6.3
-
None
Description
If you have a shared pointer to an interface, then you must assign it a shared pointer to the implementation class in order to be able to use sharedFromThis() inside the class. Example:
#include <QSharedPointer> class Interface { public: virtual ~Interface() { } virtual bool foo() = 0; }; class MyClass : public Interface, public QEnableSharedFromThis<Interface> { public: MyClass() { } bool foo() override { return !sharedFromThis().isNull(); } }; int main() { QSharedPointer<Interface> instance(new MyClass); bool bar = instance->foo(); // Returns false instance = QSharedPointer<MyClass>::create(); bar = instance->foo(); // Returns true instance.reset(new MyClass); bar = instance->foo(); // Returns false return 0; }