See also QSharedPointer and QPointer. The lifetime of an object begins after its constructor completes successfully. To complicate things, debugging reports had absolutely random pattern as well. The QSharedPointer class holds a strong reference to a shared pointer The QSharedPointer is an automatic, shared pointer in C++. So a conclusion would be: watch out for run-away. All of QList's functionality also applies to QQueue. Share. Thanks for any suggestion and comment, JulioHere's an example: void removeData() { QSharedPointer<DataPoints> dataPoint01(qobject_cast<DataPoints*>(sender())); // QList<QSharedPointer<DataPoints>> dataList; dataList. It can happen, since QObject may be destroyed by its parent. For example, a data stream that is written by a PC under Windows can be read by a Sun SPARC running Solaris. Usually one creates containers on the stack though, creating them on the heap is unidiomatic and unnecessary in almost all. append(QSharedPointer<MyObject>(new MyObject("first", 1))); list. I was reading about QSharedPointer in Qt. These are the top rated real world C++ (Cpp) examples of QSharedPointer::GetSubscriptionTypeStr extracted from open source projects. It cannot be used to dereference the pointer directly, but it can be used to verify if the pointer has been deleted or not in another context. The temporary instance of the shared pointer allocated on the heap in answer1 will be deallocated by its shared pointer. when I will print the debug message second time it shows the segmentation fault and application crashes. List of All Members for QSharedPointer. A smart pointer is an abstract data type that has all features of a standard pointer and additionally provides automatic garbage collection. The ticker of an axis can be set via QCPAxis::setTicker. h","contentType":"file. #include "employee. When the last QSharedPointer is destructed, the object gets destructed and deleted. A shared pointer holds an instance to an object that manages its own lifetime and QObjects don't!Their. 4. A more complex program sending QSharePointer objects using slots has a similar situation with GDB, that can be reproduced with the previous example. There are not so much Qt examples and demos with QSharedPointer because of the general concept for memory management in Qt using parent–child hierarchy of QObject. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. QQuickItemGragResult *result = new. 1. 1 Answer. List of all members, including inherited members; Public FunctionsA "null" QSharedPointer wraps a T* t where t equals 0/NULL/nullptr. You can rate examples to help us improve the quality of examples. C++ (Cpp) QSharedPointer::Count - 2 examples found. C++ (Cpp) QSharedPointer::SetSink - 1 examples found. Member Type Documentation typedef QSharedDataPointer:: Type. As long as there is at least one QSharedPointer pointing to an object, the object is kept around. [noexcept] const T *QSharedDataPointer:: constData const. Now I have a situation in which a class has to call a function and pass a pointer to itself. 1 Answer. 4. QSharedPointer is a template class that allows multiple objects to share ownership of a dynamically allocated object. If somehow the object/container survives so does the smart pointer and the allocated memory. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it. It behaves exactly like a normal pointer for normal purposes, including respect for constness. The QWeakPointer is an automatic weak reference to a pointer in C++. You can use smart pointers to hold you item in your QList, for example QSharedPointer<MyCustomObj>. A mutex is an object that has lock() and unlock() methods and remembers if it is already locked. Therefore, to access the pointer that QWeakPointer is tracking, you must first promote it to QSharedPointer and verify if the resulting object is null or not. g. . data (); } When you delete the pointed-to object, data () will be null. It. Previously i had done this: Code: MyObject * object; // Subclass of QObject. Unfortunately Google was unable to help me this time. QScopedPointer is a small utility class that heavily simplifies this by assigning stack-based memory ownership to heap allocations, more generally called resource acquisition is. C++ (Cpp) QSharedPointer::at - 10 examples found. Here's an example: void removeData() { QSharedPointer<DataPoints> dataPoint01(qobject_cast<DataPoints*>(sender())); // QList<QSharedPointer<DataPoints>> dataList; dataList. 4. cpp MainWindow::MainWindow () :timer2 (new QTimer) { } Alternately, if you want to create the instance in some arbitrary member function of MainWindow, use this: It's also worth reviewing initialization lists in C++ and the documentation for QScopedPointer. The problem is that this code is creating a QSharedPointer from a raw pointer, which implies ownership of the object pointed to. // OK QSharedPointer < QObject > object3(new QObject); // OK} Using a Mutex to Protect the Integrity of Data. 8. QSharedPointer:: QSharedPointer (const QWeakPointer < T > &other) Creates a QSharedPointer by promoting the weak reference other to strong reference and sharing. Equivalent to: QSharedPointer<T> other(t, deleter); this->swap(other); Returns true if the contained pointer is not nullptr. The whole point of this function is to allocate the reference count near the object instance in memory, so you have to let it do the allocation. A guarded pointer, QPointer<T>, behaves like a normal C++ pointer T *, except that it is automatically set to 0 when the referenced object is destroyed (unlike normal C++ pointers, which become "dangling pointers" in such cases). For your concrete example, you could use a QList<QSharedPointer<MyClass>> for the model and use QWeakPointer<MyClass> in the drawable classes. Both serialization and desertialization are rather simple. 2 version on Ubuntu 18. For the sake of the example: Don't return a pointer to QList<>, return the QList<> itself. See also QSharedPointer and QScopedPointer. Member Function Documentation QWeakPointer:: QWeakPointer (). There is suspicious argument this in the Team constructor that looks like a pointer to. When removeData() returns, any further attempts to reference the sender is undefined behavior. Make sure you don’t call delete on the objects. . args) \overload \since 5. It behaves exactly like a normal pointer for normal purposes, including respect for constness. [/quote] Correct. T *QWeakPointer:: data const. To complicate it even more, all debugging traces were leading to. The Q_DECLARE_METATYPE macro is necessary in both cases. Example#1. 3) Objects created by QDeclarativeEngine or Javascript owned by the. Also my first approach produces a memory leak. Returns a const pointer to the shared data object. You can also use a data stream to read/write raw unencoded binary data. A class derived from EmployeeData could override that function and return the proper polymorphic type. Sabat 10 Jan 2020, 10:52. QSharedPointer. MyObject * object; // Subclass of QObject. The requester class should also be in charge of managing the memory of the pointer it created. Examples of such functions include std::static_pointer_cast, custom comparators, or predicates. 9. QSharedPointer dynamicCast and objectCast fail on ubuntu. the above one did not compile with msvc17 and with my arm toolchain. The examples on Wikipedia makes no sense to me. So a conclusion would be: watch out for run-away. Adding a Q_DECLARE_METATYPE () makes the type known to all template based functions, including QVariant. keyToAscii (key). The QSharedPointer internals and the object are allocated in one single memory allocation, which could help reduce memory fragmentation in a long-running application. the above one did not compile with msvc17 and with my arm toolchain. 6. Children are typically added to a QObject *parent from their constructor with new QObject(parent);. If you refactor your code so that all new operator are in lines like these, all your problems will be solved. QPointer:: QPointer () Constructs a guarded pointer with value nullptr. C++ (Cpp) QSharedPointer::direction - 6 examples found. You can use this constructor with any QObject, even if they were not created with QSharedPointer. 4, but was reborn in 4. x. Use qSharedPointerCast (): QSharedPointer <Switch> mySwitchTest= qSharedPointerCast<Switch> (myState); Or call staticCast () on the smart pointer: QSharedPointer <Switch> mySwitchTest= myState. Your solution is simple. 1009. 1009. It behaves exactly like a normal pointer for normal purposes, including respect for constness. If I have to share this instance in C++, I'll use QSharedPointer or std::shared_ptr. 5. typedef QVector<QSharedPointer<Tester> > TestPointerVector;. QSharedDataPointer is a nifty way to implement copy-on-write and detaches/copies its object when it is accessed in a non-const way. I know that QVector is calling destructors for it's objects, that he is holding. QScopedPointer has its copy constructor and assignment operator disabled. The application consists of the following steps: Download images form the list of URLs specified by the user. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it. You will need to delete it yourself: ~MyClass () { delete m_process. It does not manage the object it points to. Parenting in Qt affects object freeing with some kind of pseudo garbage collection. Previously i had done this: Qt Code: Switch view. One example may be the case where you store lots of pointers to objects in a container class. You can rate examples to help us improve the quality of examples. See QWeakPointer::toStrongRef () for an example. The same is for tokencount == 1. One problem i have ran into is using signals and slots with the objects that are shared-pointed-to. // Create a fresh shared pointer in the scope QSharedPointer<uint8_t> image(new uint8_t[IMG_SIZE]); // the ring buffer can possibly be rewritten on the next usb_read() (if bufferlength = 1) so I copy. It is non-owning. This method may be prefered over using QSharedPointer, since a QExplicitlySharedDataPointer is the same size as a normal pointer. I'm trying to do the following: typedef QSharedPointer< int > SharedInt; qRegisterMetaType< SharedInt > ( "Tick" ); but when I'm trying to connect to such signal as Qt::QueuedConnection type I receive message: QObject::connect: Cannot queue. There are not so much Qt examples and demos with QSharedPointer because of the general concept for memory management in Qt using parent–child hierarchy of QObject. It is not possible to directly use static_cast, const_cast, dynamic_cast and reinterpret_cast on std::shared_ptr to retrieve a pointer sharing ownership with the pointer being passed as argument. Qt also provides QSharedPointer, an implementation of a reference-counted shared pointer object, which can be used to maintain a collection of references to an individual pointer. I have QVector<QSharedPointer<SomeData> > DataVec as a field of one class in a big objected-oriented project. Commented defines are for "not compiling" parts. The extracted content is removed automatically once the last reference. #include <QCoreApplication> #include <QThread> #include <QSharedPointer> #include ". @Yakk: Thanks for that, I've updated my answer to reflect your point. If on the other hand %h is available, the minutes will wrap around to zero after 59 and the time will carry to the hour. It just tracks whether or not it was deleted. If a ptr2's. It uses reference counting to track the number of objects sharing the pointer, and. Detailed Description. Instead, the functions std::static_pointer_cast, std::const_pointer_cast, std::dynamic_pointer_cast and std::reinterpret_pointer_cast. template<typename T >. template parameter is not a base or a derived type from. 1 Answer. This function was introduced in Qt 4. One place we have used QSharedPointer is in DataObjectTableModel, shown in Example 13. This is the pattern that the automatic data collector will look for and parse. You can rate examples to help us improve the quality of examples. MyObject * obj = sharedPointerToObject. It behaves exactly like a normal pointer for normal purposes, including respect for constness. behaves exactly like a normal pointer for normal purposes, including respect for constness. h","contentType":"file. If you want to create the instance in the constructor, use the following: // mainwindow. You can rate examples to help us improve the quality of. The QSharedPointer is an automatic, shared pointer in C++. It doesn't take ill luck: calling the destructor of an object that isn't alive is undefined behavior. A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. For large vectors, this operation can be slow (linear time), because it requires moving all the items in the vector by one position further in memory. The examples on Wikipedia makes no sense to me. {"payload":{"allShortcutsEnabled":false,"fileTree":{"src/corelib/tools":{"items":[{"name":"qalgorithms. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. QSharedPointer:: objectCast() works reliably across DLL boundaries, but QSharedPointer:: dynamicCast() and std::dynamic_pointer_cast() don’t. The exception is pointers derived from QObject: in that. When removeData() returns, any further attempts to reference the sender is undefined behavior. In this episode we will look at two Qt smart pointers - QScopedPointer and QSharedPointer. If you need a QSharedPointer, don't set the parent. [quote author="situ117" date="1304279927"] I was reading about QSharedPointer in Qt. But everytime i try to implement this i recieve a seg fault. 4. The others are more specialized. There are not so much Qt examples and demos with QSharedPointer because of the general concept for memory management in Qt using parent–child hierarchy of QObject. How can I register, for example, QSharedPointer< int > in meta type system. > You can for example return the result of qHash(sharedPointer. To have that guarantee, use toStrongRef(), which returns a QSharedPointer object. If it represents a type, it returns QMetaType::Int. 5. 1 under Ubuntu 10. The pointed-to value in the Q_ASSERT will live until the statement finishes. Simple CBOR stream decoder, operating on either a QByteArray or QIODevice. It behaves exactly like a normal pointer for normal purposes, including respect for constness. A slot is a receiving function used to get information about state changes in other widgets. QSharedPointer will delete the pointer it is holding when it goes. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. If a ptr2's template parameter is different from a ptr1's, 1008. QSharedPointer. 1 Reply Last reply . Qt also provides QSharedPointer, an implementation of a reference-counted shared pointer object, which can be used to maintain a collection of references to an individual pointer. QVector<T> used to be a different class in Qt 5, but is now a simple alias to QList. QDoubleSpinBox: See QSpinBox. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. This function was introduced in Qt 4. With new QProcess (this);, you made the new QProcess object owned by this instance of MainWindow. The QSharedPointer is an automatic, shared pointer in C++. Guarded pointers are useful whenever you need to store a pointer. QPointer:: ~QPointer () Destroys the guarded pointer. You can rate examples to help us improve the quality of. This function was introduced in Qt 5. In this example, the source object is a simple binary switch that toggles its state based on a timer. 19. Values stored in Qt containers should be of assignable data types. h","path":"src/corelib/tools/qalgorithms. It is a generic issue that you cannot have different owners of a pointer that do not know each. If we have smart pointers in Qt, why old C type pointers are preferred ? Reply Quote 0. [/quote] That is a good example to be careful with smart pointers. Code that makes use of delete are candidates for QScopedPointer usage (and if not, possibly another type of smart pointer such as QSharedPointer). But, it all depends on your use case. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. C++ (Cpp) QSharedPointer::isSelected - 12 examples found. AnotherObject * something; The c++ (cpp) qsharedpointer example is extracted from the most popular open source projects, you can refer to the following example for usage. . no known conversion for argument 1 from 'const RecordPtr {aka const QSharedPointer<MyApp::Record>}' to 'const QObject*' you are trying to pass an object of type RecordPtr to a method expecting "const QObject*". Example: Say you have Guest object with 2 inheritances: Now we can make Guest inherit from QObject and children inherit from. QSharedPointer will attempt to perform an automatic t static_cast. Several of the example programs connect the valueChanged() signal of a QScrollBar to. The interface: Model. This example creates a QSharedPointer object that references an int value. QSharedPointer<MyDataQObject> objPtr { new MyDataQObject, &QObject. combination used to implement implicit sharing, both in Qt itself and. But I've not seen it much in use in source code of Examples and Demos. C++ (Cpp) QSharedPointer::GetSubscriptionTypeStr - 2 examples found. In that case, I think we should pass by reference. publicslots: void slotCalledByScript(Y *managedBySharedPointer) { QSharedPointer<Y> yPtr =. If a new note is created, its reference is appended to the list: void Traymenu::newNote () { QSharedPointer<Note> note (new Note (this)); m_noteList << note; } For each Note-element, whichs pointers are in m_noteList, I want to get its title and. 1 Answer. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. QSharedPointer/QPointer: use SerializerBase::registerPointerConverters<T>()QSharedPointer documentation does not have any warning about pointing to QObject-derived classes. The reference count is printed to the console using the use_count() method. The pointer ptr becomes managed by this QSharedPointer and must not be passed to another QSharedPointer object or deleted. Example: QPointer < QLabel > label = new QLabel ; label - > setText( "&Status:" );. Then, a new QSharedPointer object is created that references the same int object. If T is a derived type of the template parameter of this class, QSharedPointer will perform an automatic cast. A make_shared () function and a shared pointer class are available in the standard library since C++14, so you could write: #include <memory> //. For your concrete example, you could use a QList<QSharedPointer<MyClass>> for the model and use QWeakPointer<MyClass> in the drawable classes. Here's an example: void removeData() { QSharedPointer dataPoint01(qobject_cast(sender())); // QList> dataList; dataList. other. These are the top rated real world C++ (Cpp) examples of QSharedPointer::UpdateViewSection extracted from open source projects. Member Function Documentation QSharedPointer < T > QEnableSharedFromThis:: sharedFromThis (). QSharedPointer IF you using a pointer and start giving pointer to other functions and you are passing your pointer all over. File: searchtrackmodel. QtTest. const T *QSharedDataPointer:: constData constMake a typedef for QSharedPointer<UserDataType>, and use both Q_DECLARE_METATYPE as well as qRegisterMetaType() to register it for use. As a general guideline, if you are not sharing your pointers between multiple users, use a QScopedPointer, otherwise use a QSharedPointer. This is the type of the shared data object. It should work if the code is put into one function block. This maintains a standard interface across Qt classes. [/quote] There are not so much Qt examples and demos with QSharedPointer because of the general con. com: 30. QPointer<QHash<QString, QString> > foo ( new QHash<QString, QString> () ); If you really need (smart) pointers to containers, try QSharedPointer, which doesn't require the contained object to be of any specific type. A shared pointer is null by default, or when set to 0/nullptr explicitly:C++ (Cpp) QSharedPointer::node - 2 examples found. 4. The procedure is: Define the class Employee to have a single data member of type QSharedDataPointer<EmployeeData>. Like its name indicates, the pointer value is shared among all instances of QSharedPointer and QWeakPointer. data()) > since there is a qHash function for the pointer type. Since they use the signal/slot mechanism, I must use the QObject::deleteLater() in order to properly destroy them, see for example: ~QObject(): "Deleting a QObject while pending events are waiting to be delivered can cause a. It behaves exactly. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it. [quote author="Andre" date="1306394817"]In that case, I think you need to register them. QSharedPointer Class Reference. The first MyClass object pointer 0x13defe0 is assigned to the QPointer instance, the second one (0x110f780) to QSharedPointer instance. QPointer 、 QSharedPointer 、 QWeakPointerクラスに関するQtのドキュメントを読みました。それは言う: QPointerは、Qtオブジェクトへの保護されたポインタを提供し、参照されたオブジェクトが破棄され、 "ぶら下がっているポインタ"が生成されないときに自動的に0に設定される点を除いて、通常のC. QSharedPointer:: objectCast() works reliably across DLL boundaries, but QSharedPointer:: dynamicCast() and std::dynamic_pointer_cast() don’t. The base class of all event classes. and 4. It tracks the lifetime of an object. It's a start. T must be a subclass of QObject. The QSharedPointer class holds a strong reference to a shared pointer. The one I used in my own answer does. Usually one puts this (note that the typedefed name is used as string argument): qRegisterMetaType< QSharedPointer<TestClass> > ( "SharedTestClass" );My intention was, since I had to store the actual data in another QSharedPointer, to make a connect on that shared pointer that tells the other widget. When the last associated QSharedPointer goes out of scope, the object will be deleted. It behaves exactly like a normal pointer for normal purposes, including respect for constness. This being the case, you have two ways around the problem: 1) Provide a copy constructor (which you have done) 2) Provide a specialization of qMetaTypeConstructHelper that doesn't use the copy constructor: template <> void *qMetaTypeConstructHelper<ClassA> (const ClassA *) { return new ClassA (); } Share. See QWeakPointer::toStrongRef() for an example. . I worked around this by extracting a raw pointer from the QSharedPointer: The template parameter is the type T of the class which QSharedPointer tracks. static PySide2. Just a small addition. This can be achieved by setting enabled to false before issuing a command like QCustomPlot::savePng, and setting enabled back to true afterwards. So the point is: don't use QSharedPointer just because it's smart. Are QSharedPointer in general designed to be passed through signals that way? And if so, is there a mecanism to keep a reference while it is queued? I considered the folowing solutions, but I'm not totally fine with neither of them:. C++ (Cpp) QSharedPointer::GetFormulaRadius - 2 examples found. #include <QSharedPointer> Note: All functions in this class are reentrant. Code that makes use of delete are candidates for QScopedPointer usage (and if not, possibly another type of smart pointer such as QSharedPointer). The base class tick generator used by QCPAxis to create tick positions and tick labels. This is a working example showing it calls. To avoid the cost of thread creation, a thread pool can be used. Example Before I switched to Qt, I used gtkmm where this was more usual. Passing data through threads is a common task in multi-thread programming. Previously i had done this: Qt Code: Switch view. As per the documentation of QSharedPointer, it might be deleting the pointer first time after accessing the element. It works like variables in Java and CPython, or like std::shared_ptr. ©2023 The Qt Company Ltd. So it this allows multiple pointers to point to the same class instance. It has all the features you may want in a modern pointer class: it is polymorphic, it supports static, const, and dynamic casts, it implements atomic reference-counting and thread-safe semantics, it supports. That said, your stack trace is really strange:. The example is over-engineered (why using a QSharedPointer? why capturing it by value?). in Qt-using projects. QSharedPointer < T > QEnableSharedFromThis:: sharedFromThis () If this (that is, the subclass instance invoking this method) is being managed by a QSharedPointer, returns a shared pointer instance pointing to this; otherwise returns a null QSharedPointer. std::shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. referencing it. In many cases, that UB may be innocuous, but it is UB regardless. C++ (Cpp) QSharedPointer::StopTimer - 1 examples found. ) method. to ensure that the pointers being compared are equal. wysota. Detailed Description. Yes. . The temporary instance of the shared pointer allocated on the heap in answer1 will be deallocated by its shared pointer. 209: The pointer to the object is kept here because it needs to match the actual: 210: deleter function's parameters, regardless of what template argument the: 211: last QSharedPointer instance had. If you want a container class that provides a fast prepend() function, use QList or QLinkedList instead. 5 Note This class or function is reentrant. The following chapters show an example and explain a few important details regarding the functionality and limits of the implementation. Detailed Description. h file like: #include "myclass. You can inherit this class when you need to create a QSharedPointer from any instance of a class; for instance, from within the object itself. If the reference count is zero then the object it is pointing to will be destroyed. out of scope, provided no other QSharedPointer objects are. Qt provides a number of thread synchronization constructs, you'll probably want to start with QMutex and learn more about thread-safety. And most of QObjects are created with raw new operations. You might be tempted to use QSharedPointer in this case and it would work, but remember that QSharedPointer, just like std::shared_ptr, is a lot heavier construct, as sharing in a multi-threaded world is a "far from 0" overhead thing. C++ (Cpp) QSharedPointer::getShapes - 4 examples found. Args> QSharedPointer<T> QSharedPointer<T>::create(Args &&. That said, yo. . Use this handler for pointers that were allocated with new []. But, it all depends on your use case. Re: Custom Deleter for QSharedPointer. h. Scale the images. It doesn't take ill luck: calling the destructor of an object that isn't alive is undefined behavior. In this guide, we will discuss the differences between QSharedPointer and QSharedDataPointer and show code examples. For example, canConvert(QMetaType::fromType<int>()) would return true when called on a variant containing a string because, in principle, QVariant is able to convert strings of numbers to integers. removeAll(dataPoint01); }. – Igor Tandetnik. Programming Language: C++ (Cpp) Class/Type: QSharedPointer. 212: 213: This class is never instantiated directly: the constructors and: 214In the example above, the template specialization for the clone() function calls the EmployeeData::clone() virtual function. It has a concept of ownership. These are the top rated real world C++ (Cpp) examples of QSharedPointer::isNull extracted from open source projects. So a conclusion would be: watch out for run-away. The pointed-to value in the Q_ASSERT will live until the statement finishes. If you call deleteLater () in the object's destructor and put an object on the stack - deleteLater () is called when the object goes out of scope. But just added a basic example from the docs to make things clear. This example shows how to use the QFuture, QPromise, and QFutureWatcher classes to download a collection of images from the network and scale them, without blocking the UI. You can rate examples to help us improve the quality of examples. See QWeakPointer::toStrongRef() for an example. The QSharedPointer is an automatic, shared pointer in C++. An invalid model index can be constructed. 0. The QCPGraphDataContainer is an abstract data container of QCPGraphData object, one of which will be created for each data point that we parse. That's what's meant with "object is null" isNull() and operator!() are equivalent, you can use either one. Previously i had done this: Code: MyObject * object; // Subclass of QObject. C++ (Cpp) QSharedPointer::getEndPoint - 6 examples found. In the example above, the template specialization for the clone() function calls the EmployeeData::clone() virtual function. They are often. Therefore, to access the pointer that QWeakPointer is tracking, you must first promote it to QSharedPointer and verify if the resulting object is null or not. or if you already have a reference to a pointer, then use the reset () method as follows: Qsharedfoo. In this case, this function returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or nullptr. [quote author="situ117" date="1304279927"] I was reading about QSharedPointer in Qt. h","path":"src/corelib/tools/qalgorithms. The contents of the object pointed to by the pointer should not considered shared, however: there is. Check your Options in the drop-down menu of this sections header.