Questions tagged [qsharedpointer]
QSharedPointer is a Qt class which holds a strong reference to a shared pointer.
3
votes
1answer
66 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
0answers
46 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
1answer
72 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
1answer
35 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
1answer
152 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
1answer
178 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
1answer
87 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. ...
5
votes
1answer
487 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
1answer
141 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
0answers
242 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 cast ...
0
votes
1answer
165 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
2answers
514 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 ...
2
votes
0answers
381 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 ...
1
vote
1answer
488 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
0answers
104 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
1answer
502 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
2answers
185 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
1answer
299 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
1answer
220 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
2answers
595 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
1answer
908 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
0answers
116 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
0answers
374 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
1answer
329 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;
...
3
votes
1answer
554 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
1answer
1k 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 ...
4
votes
2answers
5k 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
0answers
210 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
2answers
150 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
2answers
948 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&...
6
votes
1answer
2k 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,...
7
votes
2answers
3k 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
0answers
488 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
1answer
795 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
1answer
259 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
2answers
281 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
1answer
129 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
2answers
370 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
2answers
772 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
1answer
573 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 ...
1
vote
2answers
803 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, ...
25
votes
1answer
20k 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
1answer
2k 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, ...
0
votes
1answer
246 views
should getters from an object return references pointers or QSharedPointers?
I'm storing an object internally(private) as a QSharedPointer(so it will delete it). For the getter should I return a reference a raw pointer or a QSharedPointer?
Also I'm not sure what http://qt-...
3
votes
2answers
2k views
QSharedPointer from a raw pointer
I currently have something like this:
QSharedPointer<t> Qsharedfoo;
Now I have a raw pointer to foo as well called rawfoo. How can I make foo point own the raw pointer and start pointing to it....
1
vote
1answer
2k views
QSharedPointer::create()
In Qt 4 i have I have the following array:
QSharedPointer<unsigned char> encrypted(new unsigned char[RSA_size(publickey)]);
How can I combine the two allocations in one with the new Qt 5 ...
3
votes
2answers
2k views
Difference between QSharedPointer::isNull() and operator!()
in Qt docs we read:
bool QSharedPointer::operator! () const
Returns true if this object is null.
This function is suitable for use in if-constructs, like:
if (!sharedptr) { ... }
and
bool ...
1
vote
1answer
3k views
How can I delete QSharedPointer from container the right way
I have QVector<QSharedPointer<SomeData> > 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 ...
0
votes
0answers
341 views
Secure shared pointer for Qt
Since Qt uses its horrible archaic ptr mechanisms, using their QSharedPointer is mostly not practical.
The moment you set a QSharedPointer to nullptr while being in a slot could very well result in ...
2
votes
1answer
370 views
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 ...