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
1
vote
1 answer

QSharedPointer::create()

In Qt 4 i have I have the following array: QSharedPointer encrypted(new unsigned char[RSA_size(publickey)]); How can I combine the two allocations in one with the new Qt 5 create function? QSharedPointer QSharedPointer::create()
user3171641
  • 13
  • 1
  • 3
1
vote
1 answer

How can I delete QSharedPointer from container the right way

I have QVector > DataVec as a field of one class in a big objected-oriented project. Program gets memory overflow during cycled execution of code part, where large memory is allocated, controlled by QSharedPointers. During…
John_West
  • 2,239
  • 4
  • 24
  • 44
1
vote
1 answer

Generalizing shared pointers and QSharedPointer::data() vs shared_ptr::get()?

I made a Qt library that is built on longstanding abstractions like QSharedDataPointer and QSharedData. So when I needed an ordinary shared pointer it made sense to go with QSharedPointer for consistency. I'm now using this in a C++11 project. In…
0
votes
1 answer

How to write a custom deleter with a templateized QSharedPointer

I am trying to write a templatized wrapper to a class such that the wrapper can manage the lifespan using a shared pointer. (I can't modify the class(es) that I'm wrapping) I would like to write a custom deleter such that I can debug and validate…
Techniquab
  • 843
  • 7
  • 22
0
votes
1 answer

Using QSharedPointer as Data Model

I have an application with multiple "input widgets" written as inpependent classes, that all store a shared pointer of the respective class that's data thay show. In each of these widgets a user can see and manipulate some different data. All of…
void
  • 142
  • 9
0
votes
1 answer

Using QVector and implement a subset of QVector in good practice

Hello and good morning together, I have two questions concerning QVector and its usage. I have an own custom class. It is necessary to use QVector> or does it suffice to directly add instances to QVector like…
Findus
  • 303
  • 1
  • 4
  • 17
0
votes
1 answer

Qt slots are not called in release mode and I blame QSharedPointer

I have a problem with signal-slot mechanism, may be that it's actually a problem with QSharedPointer as smart pointers are new to me. A little explanation of the context: TCPAssociation is child class of LANAssociation. TCPClient is child class to…
smsware
  • 429
  • 1
  • 13
  • 41
0
votes
3 answers

How to create a QSharedPointer> with an initializer list?

What works In Qt 5.12.4, I try to dynamically create QSharedPointer>. I know that I can do QMap mp = { { 1, true } }; as well as dynamically with QMap* mpptr = new QMap { { 1, false } }; I know that…
darkmattercoder
  • 325
  • 6
  • 26
0
votes
1 answer

Smart pointers and avoid manual memory management when using QNetworkAccessManager

I have the following class which calls some HTTP API request to a server: class NetworkRequest : public QObject { public: NetworkRequest(QNetworkAccessManager* netManager): m_netManager(netManager){} void send(QUrl const &url){ …
reckless
  • 741
  • 12
  • 53
0
votes
0 answers

Crashes when dereferencing a QSharedPointer to a QMultiHash

I've got a QSharedPointer to a QMultiHash. When I try to get the QMultiHash from the QSharedPointer it messes up. My thinking is that the QHash part of the QMultiHash is unaccessible. QSharedPointer> aNewNodesMH(new…
Jeff
  • 95
  • 9
0
votes
1 answer

Constructor for class 'QSharedPointer' is declared 'explicit' - How to resolve this error

I get the following error when trying to use: typedef QSharedPointer CTest CTest* Module::function(params) { CTestNew* ptr = new CTestNew(params); dosomething(); return ptr; } Then replace Test* with CTest in the code. What…
Vij
  • 27
  • 1
  • 7
0
votes
1 answer

Qsharedpointer class

I am trying to use a smart pointer class in the following way class A { friend class B; virtual methods (); protected: virtual ~classA(); } class B:public QSharedPointer { class B(); ~ class B(); } I plan to replace occurrences…
Vij
  • 27
  • 1
  • 7
0
votes
1 answer

Qt 4.8.7 memory artefacts

I need to use Qt 4.8.7 for Embedded Linux to create a very simple project for testing. Project includes 2 forms - Dialog (consists of QTextEdit and button. Button clears QTextEdit and QClipboard) and MainWindow (consists of button that exec…
PMA
  • 23
  • 5
0
votes
1 answer

QEnableSharedFromThis::sharedFromThis() returns nullptr

I have a class MyClass that should be able to return this wrapped in QSharedPointer. It is my understanding (and experience) that simply creating new instances of QSharedPointer(this) is NOT the way to go. Instead The correct way…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
0
votes
1 answer

How to delete what my shared pointer is pointing to?

When I run my main methods the functions makeEmpty and remove do not work. I am converting this code from using pointers to using shared pointers and I am not very familiar with shared pointers yet. Any insight on how to do this or any solutions…
m. thomas
  • 31
  • 1
  • 3