Questions tagged [qsharedpointer]

QSharedPointer is a Qt class which holds a strong reference to a shared pointer.

Introduced in Qt 4.5 QSharedPointer class represents a strong reference to a shared pointer. It is similar to boost::shared_ptr or std::shared_ptr.

The QSharedPointer is an automatic, shared pointer in C++. It is thread-safe and operates atomically on the pointer value.

QSharedPointer holds a shared pointer by means of an external reference count.

Official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

75 questions
2
votes
2 answers

Allocating and returning from function a QSharedPointer on the stack

Unlike a dumb pointer, I would expect that I could create a QSharedPointer on the stack in a function and then return it as return value for assignment to another QSharedPointer of the same type, right? Normally, such a pointer would point to memory…
johnbakers
  • 24,158
  • 24
  • 130
  • 258
2
votes
1 answer

QSharedPointer dynamicCast and objectCast fail on ubuntu

I am using Qt 5.0.1 under Ubuntu 10.04 and in my application I need to use QSharedPointer together with the appropriate dynamic_cast (object_cast) conversions at runtime. These conversions are called in a shared object which is properly loaded at…
arms
  • 163
  • 1
  • 3
  • 9
2
votes
3 answers

Check two QSharedPointer have equal data

I have two QSharedPointer, can I check are they pointed to the same object using operator== like this QSharedPointer1 == QSharedPointer2 or I must write QSharedPointer1.data() == QSharedPointer2.data() Object that are stored in pointers have…
Littlebitter
  • 671
  • 3
  • 10
  • 19
2
votes
1 answer

Qt smart pointer equivalent of boost::shared_array?

While there exists an equivalent of boost::shared_ptr (QSharedPointer) I wasn't able to find something that resembles boost::shared_array. Of course I could use something similar to QSharedPointer > shared_vector_ptr(new…
Zeta
  • 103,620
  • 13
  • 194
  • 236
1
vote
1 answer

QPair initialization

When I use the following statement, typedef QPair test where ItemB is a smart pointer.ie typedef QSharedpointer ItemB When I instantiate test, should I provide initialization values ? eg: test Inst1(0,0); Or does QPair…
Vij
  • 27
  • 1
  • 7
1
vote
0 answers

Receiving fatal error assigning QSharedPointer in QtTest

In TestGroup_Person, when I retrieve a QSharedPointer<-JB_TableRowProt> from JB_PersonDao and assign it to QSharedPointer<-JB_TableRowProt> aGroup_Person (in .h), I then get this error in the methods of TestGroup_Person. Alternatively, if I retrieve…
Jeff
  • 95
  • 9
1
vote
5 answers

Please explain this expression

class TestPtr : protected QSharedPointer where Test is an abstract interface class. The TestPtr class should serve as the smart pointer class. Does this mean class TestPtr is derived from the class Test ? Is class test enclosed in a smart…
Vij
  • 27
  • 1
  • 7
1
vote
1 answer

Deleting a QObject that QSharedPointer is pointing to

In my project I create QObject instances and give them a parent-child relationship. I also want to keep track of some of the objects with QSharedPointer instances. When an object gets deleted, either by delete childObject; or delete parentObject;, I…
mrg95
  • 2,371
  • 11
  • 46
  • 89
1
vote
1 answer

QSharedPointer gets destroyed within emit

I am prity new on Qt an got some issues with QSharedPointer passing around within signals. I am working with two threads (UI and a worker). The worker sends signals to the UI using signals that contain QSharedPointer of a custom QObject: class…
Myon
  • 937
  • 13
  • 23
1
vote
4 answers

How to prevent deletion of pointers managed by a QSharedPointer

I have some intermittent segmentation faults in a Qt application. I think the problem is related to our (bad) use of QSharedPointer. The Qt Documentation states : QSharedPointer::QSharedPointer ( T * ptr ) : Creates a QSharedPointer that points…
Symbiosoft
  • 4,681
  • 6
  • 32
  • 46
1
vote
2 answers

Does the number of references change when calling data() of a qsharedpointer

If I write this code: QSharedPointer ptr(new int()); The number of references pointing to the integer is 1. But when I call data() like this: QSharedPointer ptr(new int()); int* ptr2 = ptr.data(); Is the number of references 1…
Random Coder 99
  • 376
  • 1
  • 15
1
vote
1 answer

Segmentation fault when accessing QSharedPointer object

I have written a small sample application code as below. #include #include #include class INav { public: virtual int getdata() = 0; virtual void setdata(int a) = 0; }; class Nav : public INav { …
Swapnil
  • 1,424
  • 2
  • 19
  • 30
1
vote
2 answers

Function which returns a QList

I have the following classes class LMJEntity : public QObject { Q_OBJECT Q_PROPERTY(int Id READ getId WRITE setId) }; class LMJDataMapper : public QObject { Q_OBJECT virtual QList *findAll(LMJPaging *paging){ …
aldo
  • 312
  • 3
  • 12
1
vote
1 answer

Objects creation and members declaration in C++

I come from a Java background and I recently started to learn Qt with C++. While doing some coding a few doubts about objects creation and members declaration have come to me: Supposing I have a class declared as follows: ClassA.h: class ClassA…
1
vote
2 answers

QSharedPointer does not return false

I currently have something like this QSharedPointer cv; This shared pointer is used as cV = QSharedPointer(new QMainWindow(p)); cV->setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose); cV->show(); Now if I close the the…
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158