Questions tagged [qsharedpointer]
QSharedPointer is a Qt class which holds a strong reference to a shared pointer.
75
questions
0
votes
1
answer
26
views
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 ...
0
votes
1
answer
289
views
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 ...
0
votes
1
answer
243
views
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<QSharedPointer<Class*>> or does it ...
0
votes
1
answer
104
views
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 ...
0
votes
3
answers
746
views
How to create a QSharedPointer<QMap<a,b>> with an initializer list?
What works
In Qt 5.12.4, I try to dynamically create QSharedPointer<QMap<int,bool>>. I know that I can do
QMap<int, bool> mp = { { 1, true } };
as well as dynamically with
QMap&...
0
votes
1
answer
229
views
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(...
0
votes
0
answers
110
views
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&...
4
votes
1
answer
965
views
How to properly use destructors with QSharedPointer<QObject> AFTER the exec loop is stopped?
Good Morning everyone,
I am using QSharedPointer with my classes derived from QObject. Since they use the signal/slot mechanism, I must use the QObject::deleteLater() in order to properly destroy ...
1
vote
0
answers
355
views
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 ...
1
vote
1
answer
1k
views
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 ...
0
votes
1
answer
59
views
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 ...
1
vote
1
answer
1k
views
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 ...
0
votes
1
answer
694
views
QEnableSharedFromThis::sharedFromThis() returns nullptr
I have a class MyClass that should be able to return this wrapped in QSharedPointer<MyClass>.
It is my understanding (and experience) that simply creating new instances of QSharedPointer<...
0
votes
1
answer
433
views
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. ...
6
votes
1
answer
2k
views
Good practice for QSharedPointer as method parameter or return value of a method?
Is there any good practice or regulation on how to use a QSharedPointer object as method parameter or return value of a method ?
By value:
LMNode::setParent(QSharedPointer<LMNode> parent)
{
...
0
votes
1
answer
403
views
Pass QNetworkReply pointer to QSharedPointer
One question about use of QSharedPointer in following scenario:
I have a class with two QSharedPointers private class members:
class xy{
...
private:
QSharedPointer<QNetworkAccessManager>...
0
votes
0
answers
766
views
Save QList<QSharedPointer<MyClass>> as QVariant
I have a problem saving a QList of QSharedPointer< MyClass > as QVariant in a derived QGraphicsItem class. MyClass is an abstract base class used as an interface. I made this to be able to up ...
0
votes
1
answer
376
views
Seg Fault when using QSharedPointers in qt5
I'm using qt5.5.1 with qt-creator 3.5.1 and am trying to set a style on a GeoDataPlacemark with a GeoDataStyle. It used to work fine, but after the Marble update to use shared pointers instead of ...
0
votes
2
answers
2k
views
life cycle of QSharedPointer or std::shared_ptr
in my application
I've a MainWindow (which is a QtMainWindow class) and a Acquisiton class (which is a QThread class)
Here my very simplified Acquisiton class
//entry point of the thread
void ...
3
votes
0
answers
1k
views
reference count number for QSharedPointer
The way std::shared_ptr has a use_count function which returns the number of shared_ptr objects referring to the same managed object; in the same way how can we get the reference count for a ...
2
votes
1
answer
1k
views
this pointer and QSharedPointer
I have a tree-node like class called Message which looks like this:
class Message
{
public:
using Ptr = QSharedPointer<Message>;
public:
explicit Message();
explicit Message(...
0
votes
0
answers
218
views
Wriring binary data from QSharedPointer<float> gives unexpected file size
My issue at the moment is essentially that I can't seem to be able to write all the data that I want to disk.
What I am trying to do is saving float values in binary format to disk, one after the ...
0
votes
1
answer
1k
views
How can I delete a QSharedPointer
I have written a wrapper around QTextEdit to use it like a QIODevice. I want to be able to use multiple wrapper with the same QTextEdit, so I may use different text color with each wrapper.
To make ...
1
vote
2
answers
540
views
Does the number of references change when calling data() of a qsharedpointer
If I write this code:
QSharedPointer<int> ptr(new int());
The number of references pointing to the integer is 1.
But when I call data() like this:
QSharedPointer<int> ptr(new int()...
3
votes
1
answer
828
views
QSharedPointer without the thread-safety overhead?
I need to use a QSharedPointer for the reference counting, but I'll use it in a single-thread application so I don't want the thread-safety overhead (which I assume is fairly expensive).
Is there a ...
3
votes
1
answer
482
views
Which memory management method should we use in Qt?
I'm quite new to programming as I'm still learning how to code efficiently so my question may seem a little bit strange.
As I'm learning how to code with Qt, I know that Qt has a memory management ...
8
votes
2
answers
1k
views
Why does QSharedPointer<T>::create call destructor of incomplete object?
I have following code example:
#include <QCoreApplication>
#include <QSharedPointer>
#include <QDebug>
#include <memory>
class A
{
public:
A()
{
throw 1;
...
4
votes
1
answer
2k
views
Understanding QScopedPointer passing by reference
I've been trying to understand how to pass this as a const reference.
I have the following class:
class DBContext : public QObject
In my class MainWindow I define it as folows:
private:
...
0
votes
0
answers
216
views
QSharedPointer getting destroyed early
I am using QSharedPointer for an object which contains slot function. My expectation is that even though the object that contains this pointer get destroyed but it would live on and process the ...
0
votes
0
answers
768
views
Iterating over Qmap with QSharedPointers as values
I have a QMap that includes QSharedPointers as values. Everytime I try to loop through the map and qDebug the results I'm getting memory handling erros.
Values of the map are objects of Team class ...
1
vote
1
answer
864
views
Segmentation fault when accessing QSharedPointer object
I have written a small sample application code as below.
#include <QCoreApplication>
#include <QSharedPointer>
#include <QDebug>
class INav
{
public:
virtual int getdata() = 0;
...
4
votes
1
answer
1k
views
QCache and QSharedPointer
The problem is, that I have a QVector of QSharedPointer and I want to put part of them to my QCache. How can I insert a shared pointer to QCache? What happens if I set the pointer to my cache but ...
0
votes
1
answer
2k
views
QList::contains with a QSharedPointer
So I have a class which has an id data member and I'm using it in a QList<QSharedPointer<MyClass>> and I'm unsure about how to go about checking to see if there's an existing id in that ...
8
votes
2
answers
10k
views
Does Qt applications have automatic garbage collection?
I am researching this but I don't see a conclusive answer. Does a Qt widget application clean up the memory when it exits? Does it make any difference deriving from QObject? If there is garbage ...
0
votes
0
answers
339
views
What is the cost of calling member function via shared pointer?
It is often stated that dereferencing a smart pointer does not have notable performance impacts. (For example here: C Smart Pointer Performance)
I am now wondering if this is really true. I ...
3
votes
2
answers
173
views
Only plain pointers used in Qt API
I've been working with Qt for somedays and I wonder why all their API uses plain pointers instead of their own smart pointers like QSharedPointer.
Wouldn't it be more consistent to use them?
1
vote
2
answers
2k
views
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&...
8
votes
1
answer
4k
views
Where is Qt’s PointerToMemberFunction defined?
In this question I was able to adapt the QObject method
QMetaObject::Connection
QObject::connect(const QObject * sender,
const char * signal,
const QObject * receiver,
const char * method,...
10
votes
2
answers
7k
views
Attaching signals and slots to an object within a QSharedPointer
My application contained several functions like this:
void SomeClass::set_data_provider(DataProvider *data_provider)
{
connect(data_provider, SIGNAL(data_available(int)),
this, SLOT(...
0
votes
0
answers
825
views
Qt Signal: Dereference QSharedPointer
I have a class Historymanager, that has an attribute of type QUndoStack.
I can get the undoStack with a getter that returns
QSharedPointer<QUndoStack>
Now in a different class C, I have ...
2
votes
1
answer
2k
views
Managing QAbstractItemModel data in QSharedPointers
In c++ Qt, I like managing my heap memory with QSharedPointers, but can/should one also use them for managing data in a QAbstractItemModel?
For example, one can have a list of QStrings QList<...
1
vote
1
answer
404
views
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 ...
6
votes
2
answers
442
views
Qt equivalent to boost::ptr_vector?
I need a pointer container that takes ownership of the pointers - i.e. when an element is removed, or the container goes out of scope, it frees all its pointers, like in boost::ptr_vector.
QList<...
2
votes
1
answer
226
views
Why there is no overloaded operator T* () in class QSharedPointer
However, class QSharedDataPointer has it.
I always have to define a Class::pointer typedef for shortance and create a pointer with Class::pointer(new Class).
Does anyone know the reasoning for this?...
1
vote
2
answers
831
views
QSharedPointer does not return false
I currently have something like this
QSharedPointer<QMainWindow> cv;
This shared pointer is used as
cV = QSharedPointer<QMainWindow>(new QMainWindow(p));
cV->setAttribute(Qt::...
4
votes
2
answers
1k
views
Pool of QObject instances
I got a problem I'm not sure how to solve..
We have generic objects pool. When object is requested the pool returns QSharedPointer to the first available instance, with custom Deleter specified. The ...
6
votes
1
answer
952
views
Making a QSharedPointer<void>
For historical reasons, I use QSharedPointer<T> in my software. At some points, we want to store boost::shared_ptr<T> that point to the same data, and which should keep alive the instances ...
2
votes
2
answers
2k
views
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, ...
46
votes
2
answers
38k
views
What is the difference between QPointer, QSharedPointer and QWeakPointer classes in Qt?
I have read from the Qt documentations about QPointer, QSharedPointer and QWeakPointer classes. It says:
QPointer is a template class that provides guarded pointers to Qt objects and behaves like a ...
0
votes
1
answer
3k
views
Access to referenced elements in QList and QSharedPointer
There is a QList member variable named m_noteList containing QSharedPointer elements of class Note.
private:
QList< QSharedPointer<Note> > m_noteList;
If a new note is created, ...