Qsharedpointer example. 4. Qsharedpointer example

 
4Qsharedpointer example qt

QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it. 04: class QSharedPointer<VideoItemPrivate> has no member named ‘get’ Hello everyone, I'm trying to install gst-plugins-good 1. This helps. If you have 2 separate threads that are doing. QSharedPointer works with forward declarations, so I'd guess you're using it incorrectly; consider giving a minimal example that can be compiled (and more importantly doesn't require us to guess about the types). The QSharedPointer is an automatic, shared pointer in C++. Then, a new QSharedPointer object is created that references the same int object. Example usage - #include <QSharedData> #include <QString> class EmployeeData : public QSharedData { public: EmployeeData() : id(-1) { } EmployeeData(const EmployeeData &other) : QSharedData(other), id(other. template parameter is not a base or a derived type from. You can rate examples to help us improve the quality of examples. static PySide2. Immediately after construction both pointers go out of scope. The problem is that this code is creating a QSharedPointer from a raw pointer, which implies ownership of the object pointed to. It doesn't do any owning duties. Qt Base (Core, Gui, Widgets, Network,. But you might miss the more convenient BlockingQueue in Java/Python. So QSharedPointer was shelved for 4. This function was introduced in Qt 5. C++ (Cpp) QSharedPointer::GetP2 - 2 examples found. This function was introduced in Qt 6. 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. It is a bug if you put just a pointer to your item to QChache and at the same time such pointer is managed by QSharedPointer. All of QList's functionality also applies to QQueue. h","contentType":"file. This example creates a QSharedPointer object that references an int value. I have a class and I want to use it in a Qvariant, therefore I need to Declare and Register the Meta type. QSharedPointer is a smart pointer class in the Qt library. How To Use Managed Pointers In C++ and Qt. For example, consider a segment which directly goes from region 4 to 2 but originally is far out to the top left such that it doesn't cross region 5. 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. Smart pointers facilitate the dynamic memory operations. But I've not seen it much in use in source code of Examples and Demos. Most of the time it is not a good idea to use raw pointers (in modern C++). Be carefull in Qt to combine smart pointers and QObjects parenting. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. /blocking_queue. I would still recommend you to use 2/3, as. The QWeakPointer is an automatic weak reference to a pointer in C++. [/quote] That is a good example to be careful with smart pointers. It should work if the code is put into one function block. 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. 04 and in my application I need to use QSharedPointer together with the appropriate dynamic_cast (object_cast) conversions at runtime. The exception is pointers derived from QObject: in that. The shared pointer will automatically destroy its contents only when there are no shared pointers referencing the object originally created for the shared pointer. QList<T> and QVarLengthArray<T> provide similar APIs and functionality. If it represents a type, it returns QMetaType::Int. Modifying the data in the container will then affect all curves that share the container. Detailed Description. [quote author="situ117" date="1304279927"] I was reading about QSharedPointer in Qt. These are the top rated real world C++ (Cpp) examples of QSharedPointer::SetSink extracted from open source projects. Hi all. This function was introduced in Qt 5. . C++0x smart pointers std::shared_ptr<> The shared_ptr is a reference-counted pointer that acts as much as possible like a regular C++ data pointer. Examples at hotexamples. This can be achieved by setting enabled to false before issuing a command like QCustomPlot::savePng, and setting enabled back to true afterwards. Adding a Q_DECLARE_METATYPE () makes the type known to all template based functions, including QVariant. 1. So the point is: don't use QSharedPointer just because it's smart. QPointer is not a smart pointer. It stores its items in adjacent memory locations and provides fast index-based access. In the example above, the template specialization for the clone() function calls the EmployeeData::clone() virtual function. I was reading about QSharedPointer in Qt. 04 and in my application I need to use QSharedPointer together with the appropriate dynamic_cast (object_cast) conversions at runtime. It's possible that your first thread will execute the if statement, then the other thread will delete your label, and then you will be inside of your if statement and crash. So QSharedPointer was shelved for 4. You can rate examples to help us improve the quality of examples. What is the point of emitting a QSharedPointer? The worker thread reads the files computes the data allocates and fills the memory with data, wraps it in QSharedPointer and passes it to the mainThread, which is used for plotting. That said, your stack trace is really strange:. For. The QSharedPointer class holds a strong reference to a shared pointer. One example may be the case where you store lots of pointers to objects in a container class. However, since, in this example, the reference count is exactly 1, it doesn't make a difference. A typical application of this ticker is to make an axis only display integers, by setting the. Create an object, and then use the serializer as follows:. get ()); Have a look at the documentation of std::make_shared (for example here ). My app uses QSharedPointers throughout the C++ API, where instead of returning an object, it usually returns a smart pointer to it and every class has an accompanying typedef for convenience. Just a small addition. The examples on Wikipedia makes no sense to me. You can rate examples to help us improve the quality of examples. I am using Qt 5. Several GBs of memory are en vogue today, but ultimately you can drain any big pond (as long as you do not call it ocean) ;-) [/. MyObject * object; // Subclass of QObject. Study Resources. Examples and Tutorials Supported Platforms What's new in Qt 6 Qt Licensing Overviews Development Tools User Interfaces Core Internals. You will need to delete it yourself: ~MyClass () { delete m_process. QSharedPointer<QMap<int, bool>> mpsptr = QSharedPointer<QMap<int, bool>>::create (QMap<int, bool> { {1, false}}); Ok, I found an answer that works for me. A mutex is an object that has lock() and unlock() methods and remembers if it is already locked. It uses reference counting to track the number of objects sharing the pointer, and. Specialized axis ticker with a fixed tick step. Maybe I have bad expressed. QSharedPointer. These are the top rated real world C++ (Cpp) examples of QSharedPointer::Count extracted from open source projects. x. If somehow the object/container survives so does the smart pointer and the allocated memory. Call doc:QSharedPointer :: data () to get a pointer to the referenced class; Make sure the QML engine doesn't assume ownership: doc:QDeclarativeEngine :: setObjectOwnership (P). 4, but was reborn in 4. This page describes the handling of object ownership/lifetime in the Qt Promise library. You shouldn't do that even from C++. Ah, when the function actually needs to manipulate the smart pointer itself. QPointer 、 QSharedPointer 、 QWeakPointerクラスに関するQtのドキュメントを読みました。それは言う: QPointerは、Qtオブジェクトへの保護されたポインタを提供し、参照されたオブジェクトが破棄され、 "ぶら下がっているポインタ"が生成されないときに自動的に0に設定される点を除いて、通常のC. QWeakPointer objects can only be created by assignment from a QSharedPointer. 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. The source can be found in the examples directory: examples/tutorials/threads/ Example 1: Using the Thread Pool. When the code block containing ptr2 ends, its reference. template <typename InputIterator>. 8. Unfortunately Google was unable to help me this time. T must be a subclass of QObject. All of QList's functionality also applies to QQueue. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. 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. One problem i have ran into is using signals and slots with the objects that are shared-pointed-to. C++ (Cpp) QSharedPointer::Count - 2 examples found. . For some reason, there are very few examples out there on how to use QSharedPointer, so i find myself posting here. Use this handler for pointers that were allocated with new []. The pointed-to value in the Q_ASSERT will live until the statement finishes. The following examples can all be compiled and run independently. 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. For some reason, there are very few examples out there on how to use QSharedPointer, so i find myself posting here. I read the documentation, searched for examples which fit my needs and experimented with QScoped and QSharedPointer, but couldn't find a fullfilling solution for me. The QPointer class is a template class that provides guarded pointers to QObject. The QSharedPointer is an automatic, shared pointer in C++. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. out of scope, provided no other QSharedPointer objects are. Detailed Description. ) summary refs log tree commit diff statsIn summary, you would need to go through the constructor and operator= as follows: Qsharedfoo = QSharedPointer<T> (rawfoo); // operator= () overload. Here is an example of two processes working in parallel: one running the spreadsheet program; one running a media player. Before drawing you would create a local QSharedPointer<MyClass> in the drawing function and check if it is valid. The receiver reads the result data. QCborMap::Iterator class provides an STL-style non-const iterator for QCborMap. If T is a derived type of the template parameter of this class, QSharedPointer will perform an automatic cast. @xylosper said in How to manage QObject instance which is shared among lots of C++/QML places:. }; Q_DECLARE_METATYPE (blabla) But this code is giving me Error: In copy constructor ‘QThread::QThread (const QThread&)’: instantiated from ‘void. 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. cpp Project: Samt43/QmlMusicPlayerUIQSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. See Customizing QDockWidget for an example. The normal pattern is to put the new statement inside the smart pointer's constructor, like this: QSharedPointer<Obj> p (new Obj (2)); That way you never have a reference to the naked pointer itself. In that case, I think we should pass by reference. Log in JoinPimpl + QSharedPointer - Destructor = Disaster. The object guarded by QSharedPointer is meant to be deleted by QSharedPointer itself when all owners go out of scope. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. The QSharedPointer class holds a strong reference to a shared pointer. QSharedPointer. The example is over-engineered (why using a QSharedPointer? why capturing it by value?). The application is working as expected (creating and destroying the objects). See QWeakPointer::toStrongRef () for an example. As long as the shared pointer is in static mutexes map, it will never be deallocated, and the lifetime of mutexes is the lifetime of the program. It behaves exactly like a normal pointer for normal purposes, including respect for constness. The latter is almost a drop-in replacement for the former, except that you can’t pass a QSharedPointer to QObject::connect. QSharedPointer<A> pA1 (new A, & A ::f); To copy to clipboard, switch view to plain text mode. Since a QSharedPointer is used, multiple QCPGraphs may share the same data container safely. A slot is a receiving function used to get information about state changes in other widgets. It behaves exactly like a normal pointer for normal purposes, including respect for constness. QSharedPointer:: objectCast() works reliably across DLL boundaries, but QSharedPointer:: dynamicCast() and std::dynamic_pointer_cast() don’t. One example may be the case where you store lots of pointers to objects in a container class. One problem i have ran into is using signals and slots with the objects that are shared-pointed-to. This function was introduced in Qt 4. is not possible perform some atomic operation on two threads with two core processor at the same time. The code the compiler generates for QScopedPointer is the same as when writing it manually. This is useful, for instance, for calling deleteLater () on a QObject instead: QSharedPointer<MyObject> obj = QSharedPointer<MyObject> (new MyObject, &QObject::deleteLater); An alternative is using QPointer instead of QSharedPointer, citing the documentation: The QPointer class is a template class that provides guarded. The memory corruption can happen if Team object is destroyed before reading its pointer from QMap. Previously i had done this: Code: MyObject * object; // Subclass of QObject. In this episode we will look at two Qt smart pointers - QScopedPointer and QSharedPointer. Example: QPointer < QLabel > label = new QLabel ; label - > setText( "&Status:" );. If the type is an enumeration, flags() contains QMetaType::IsEnumeration. [noexcept] const T *QSharedDataPointer:: constData const. 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. In a related question: Waiting slots to be executed before quitting. If ptr2's template parameter is different from ptr1's, QSharedPointer will attempt to perform an automatic static_cast to ensure that the pointers being compared are equal. 3, setting a stylesheet on a QLabel automatically sets the QFrame::frameStyle property to QFrame::StyledPanel. In this installment, we will look at how to use Open Asset Import Library (Assimp) (1) to load 3D models from some common 3D model formats. Detailed Description. There is a QList member variable named m_noteList containing QSharedPointer elements of class Note. See full list on doc. 1 Answer. : QSharedPointer (new MyGizmo). 4. In this case, this function returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or nullptr. A little example would be. sorry I couldn't understand ur example. The QSharedPointer is an automatic, shared pointer in C++. QExplicitlySharedDataPointer (QESDP) is a cousin of QISDP with the. When an object gets deleted, either by delete childObject; or delete parentObject;, I would like the QSharedPointer instances to return true when calling isNull(). 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. A more complex program sending QSharePointer objects using slots has a similar situation with GDB, that can be reproduced with the previous example. 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. Someone has to manage the memory. Note that QWeakPointers created this way on arbitrary QObjects usually cannot be promoted to QSharedPointer. See also QSharedPointer and QScopedPointer. As reference the example tested on cross environment using GDB:Here is a minimal example: #include <QSharedPointer> struct A {}; int main(int argc, char *argv[]) { auto ca = QSharedPointer<const A>::create(); return 0; } Here is one file (not minimal) example but with few working cases, 2 not working and a debug. Resets this QSharedPointer object to point to t instead. 1 under Ubuntu 10. I like passing data between threads using QSharedDataPointer or QSharedPointer. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other. 2 Answers Sorted by: 4 You can create a custom connect function: template<class T> bool my_connect (const QSharedPointer<T> &sender, const char. behaves exactly like a normal pointer for normal purposes, including respect for constness. Detailed Description. Code that makes use of delete are candidates for QScopedPointer usage (and if not, possibly another type of smart pointer such as QSharedPointer). all provide a data() function to access the underlying data of a Qt class. Detailed Description. Each QCPAxis has an internal QCPAxisTicker (or a subclass) in order to generate tick positions and tick labels for the current axis range. But we don't use smart pointers in Qt much, due to parent-driven memory model. To complicate things, debugging reports had absolutely random pattern as well. One problem i have ran into is using signals and slots with the objects that are shared-pointed-to. I use elements of the list by creating a new (not a keyword) QSharedPointer<MyClass> newPointer = list. Show the scaled images in a grid layout. To avoid passing raw pointers around I have changed all occurrences of DataProvider * to QSharedPointer<DataProvider>. 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). QExplicitlySharedDataPointer, QScopedPointer, and QSharedPointer. If you want to create the instance in the constructor, use the following: // mainwindow. Share. The application consists of the following steps: Download images form the list of URLs specified by the user. > If you don't believe this matters, see comment in qdatetime. The QSharedPointer is an automatic, shared pointer in C++. {"payload":{"allShortcutsEnabled":false,"fileTree":{"src/corelib/tools":{"items":[{"name":"qalgorithms. Also my first approach produces a memory leak. As reference the example tested on cross environment using GDB:I'm trying to use QSharedPointer to define an object that will be created in a thread that will emit a signal to another thread. Example. The QSharedPointer is an automatic, shared pointer in C++. Previously i had done this: Qt Code: Switch view. Both serialization and desertialization are rather simple. centralwidget = std::make_shared<QWidget> (MainWindow); verticalLayout = std::make_shared<QVBoxLayout> (centralwidget. You will need to delete it yourself: ~MyClass () { delete m_process. Example: QPointer < QLabel > label = new QLabel ; label - > setText( "&Status:" );. That said, your stack trace is really strange:. the above one did not compile with msvc17 and with my arm toolchain. example, this allows calling QObject::deleteLater() on a given object. 5. detach from the underlying data. I have QList<QSharedPointer<MyClass>>. These are the top rated real world C++ (Cpp) examples of QSharedPointer::getShapes extracted from open source projects. . But indeed Qt is leaking the functor object. QSharedPointer is a smart pointer class in Qt that provides shared ownership of objects. I've been playing with null d pointers for the past 3 years and I've never made it work and I wasn't even trying to keep BC. It behaves exactly like a normal pointer for normal purposes, including respect for constness. One place we have used QSharedPointer is in DataObjectTableModel, shown in Example 13. This function is obsolete. Code that makes use of delete are candidates for QScopedPointer usage (and if not, possibly another type of smart pointer such as QSharedPointer). 8. ) summary refs log tree commit diff statsQMetaType::construct (), QMetaType::sizeOf (), and QMetaType::alignOf. [quote author="koahnig" date="1309429658"] Well, if you are not careful enough, the run-away container may get you ultimately. I know the QSharedPointer object gets deleted once the function goes out of scope in the test function() which would decrement the reference count, but would the. Maybe you want to collect for example "time:", "accuracy:" or "position:" samples for your particular use case. The procedure is: Define the class Employee to have a single data member of type QSharedDataPointer<EmployeeData>. C++ (Cpp) QSharedPointer::direction - 6 examples found. See QWeakPointer::toStrongRef() for an example. 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. Args> QSharedPointer<T> QSharedPointer<T>::create(Args &&. This looks to me as a Bug in Qt but I couldn't find an issue and I am not sure if some compiler settings are wrong. QSharedPointer. An. Here is my class function: template<class T> QSharedPointer<T> getObjectWithId ( int id ) { QSharedPointer<SqlObject> obj = getObjectWithId ( T::staticMetaObject. 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*". QSharedPointer:: QSharedPointer (const QWeakPointer < T > &other) Creates a QSharedPointer by promoting the weak reference other to strong reference and sharing. QQueue inherits from QList. If we have smart pointers in Qt, why old C type pointers are preferred ? Reply Quote 0. See also QSharedPointer and QScopedPointer. Of course this can be extended with more tags such as "sample:" if you want to collect many different sets of data at once. File: searchtrackmodel. QSharedPointer의 주요 기능 중 하나는 스레드로부터 안전하다는 것입니다. Also, by overloading the operator, it's very easy to. 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 QSharedPointer holding a null pointer. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. std::weak_ptr<> A. However, by that time, a. 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. It is ok to obtain the value of the pointer and using that value itself,. C++ (Cpp) QSharedPointer::getEndPoint - 6 examples found. Since that method takes a QSharedPointer<QCPAxisTicker>,. You can rate examples to help us improve the quality of examples. These conversions are called in a shared object which is properly loaded at runtime. append(QSharedPointer<MyObject>(new MyObject("second", 2))); Share. In that case, I think you need to register them. But in addition, QQueue provides three convenience functions. The contents of the object pointed to by the pointer should not considered shared, however: there is. In many cases, that UB may be innocuous, but it is UB regardless. QSharedPointer will delete the pointer it is holding when it goes out of scope, provided no other QSharedPointer objects are referencing it. // OK QSharedPointer < QObject > object3(new QObject); // OK} Using a Mutex to Protect the Integrity of Data. QSharedPointer, like QScopedPointer, is a smart pointer that deletes its referenced object, but copies are permitted, and the QSharedPointer keeps a reference count. The same question about Qt equivalent - QSharedPointer. You can rate examples to help us improve the quality of examples. That said, your stack trace is really strange:. 1 Answer. h","path":"src/corelib/tools/qalgorithms. It can happen, since QObject may be destroyed by its parent. This allows a safely shared pointer that can be used on objects that get passed around by reference like in C#. QSharedPointer will attempt to perform an automatic t static_cast. Several shared_ptr objects may own the same object. C++ (Cpp) QSharedPointer::StopTimer - 1 examples found. io First of all, could anyone please give me an example where you would ACTUALLY use shared pointers. args) \overload \since 5. The pointer ptr becomes managed by this QSharedPointer and must not be passed to another QSharedPointer object or deleted. Is this correct? Because the image is so large, I don't want do copies of it and I want it to stay alive until all the. 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. The lifetime of an object begins after its constructor completes successfully. If you refactor your code so that all new operator are in lines like these, all your problems will be solved. Only the MyClass object controlled by the QSharedPointer gets deleted. QSharedPointer guarantees that the object isn't deleted, so if you obtain a non-null object, you may use the pointer. 1 under Ubuntu 10. Expert Help. : QFrame: Supports the box model. Example: QPointer < QLabel > label = new QLabel ; label - > setText( "&Status:" );. C++ (Cpp) QSharedPointer::SetSink - 1 examples found. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. #include "employee. [explicit] template <typename D, if_same_type<D>> QScopedArrayPointer:: QScopedArrayPointer (D *p) Constructs a QScopedArrayPointer and stores the array of objects pointed to by p. Call doc:QSharedPointer :: data () to get a pointer to the referenced class; Make sure the QML engine doesn't assume ownership: doc:QDeclarativeEngine :: setObjectOwnership (P). Member Function Documentation QWeakPointer:: QWeakPointer (). I also want to keep track of some of the objects with QSharedPointer instances. That said, your stack trace is really strange:. qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. The base class of all event classes. Here's an example: void removeData() { QSharedPointer<DataPoints> dataPoint01(qobject_cast<DataPoints*>(sender())); // QList<QSharedPointer<DataPoints>> dataList; dataList. QSharedPointer:: objectCast() works reliably across DLL boundaries, but QSharedPointer:: dynamicCast() and std::dynamic_pointer_cast() don’t. The item object can be destroyed by QSharedPointer destructor, so QChache will have invalid pointer. args) overload since 5. com: 30. [quote author="Andre" date="1306394817"]In that case, I think you need to register them. As is stated in Qt documentation the == operator of QSharedPointer returns true if the values of the two managed raw pointers have the same value. See also append() and insert(). QSharedPointer<MyClass> mc (new MyClass ()); mc->testSharedThis ();The code the compiler generates for QScopedPointer is the same as when writing it manually. 5 Note This class or function is reentrant. So a conclusion would be: watch out for run-away. Member Function Documentation QWeakPointer:: QWeakPointer (const QSharedPointer < T > &other)QtのAPIのドキュメントに、thread-safeと書いてない限りは、QMutex等を使って自分で排他をする必要がある。. It behaves exactly. Usually one creates containers on the stack though, creating them on the heap is unidiomatic and unnecessary in almost all. 9 on Ubuntu 18. #include <QSharedPointer> #include <memory>. e. So a conclusion would be: watch out for run-away. The problem of owner ship of the memory is avoided. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. e. If used in this way, you can pass around these references and use them like pointers, and. . New QModelIndex objects are created by the model using the QAbstractItemModel::createIndex () function. 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. These are the top rated real world C++ (Cpp) examples of QSharedPointer::at extracted from open source projects. However, when I try to debug using GDB, the debugger receives segmentation faults. 11. That said, your stack trace is really strange:. What I did: @APIRequest::APIRequest () {. The exception is pointers derived from QObject: in that. template<class T> QSharedPointer<T> I checked a bit on StackOverflow but others examples are really complicated. insert(0, value). qRegisterMetaType< QSharedPointer<TestClass> >("SharedTestClass"); in main() not as a global variable. 1 Answer. QSharedPointer will delete the pointer it is holding when it goes. You can rate examples to help us improve the quality of examples. It behaves exactly like a normal pointer for normal purposes, including respect for constness. Since the ownership of most objects of Qt Promise is shared between multiple objects, the library uses Qt's smart pointer class QSharedPointer to manage the lifetime of the objects.