Questions tagged [qscopedpointer]

QScopedPointer is a class from the Qt Toolkit which stores a pointer to a dynamically allocated object, and deletes it upon destruction.

Documentation can be found here (Qt4) and here (Qt5).

18 questions
7
votes
3 answers

Create an instance of QScopedPointer later

For example here is my code QScopedPointer timer2(new QTimer); But I want to define QScopedPointer timer2; in mainwindow.h and create an instance timer2(new QTimer); in the mainwindow.cpp How?
6
votes
2 answers

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 > doesn't work (compile…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
5
votes
1 answer

QList of QScopedPointers

I'm trying to store QScopedPointers in a QList. I found this comment One can also use QList >. – Kuba Ober Jan 14 '14 at 18:17 (first comment on this answer: https://stackoverflow.com/a/21120575/3095014) and this post…
avb
  • 1,701
  • 5
  • 22
  • 37
4
votes
1 answer

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: QScopedPointer dbContext; How Storage class…
adviner
  • 3,295
  • 10
  • 35
  • 64
4
votes
1 answer

unique_ptr and passing to connect

In my code std::unique_ptr myNetworkAccessManager; ... myNetworkAccessManager.reset(new QNetworkAccessManager(this)); QObject::connect(myNetworkAccessManager.get(), SIGNAL(finished(QNetworkReply *)), this,…
adviner
  • 3,295
  • 10
  • 35
  • 64
3
votes
0 answers

Is it possible to have a QList of QScopedPointer of some abstract class?

I want to have a QList or QVector in a class that it has a constant number of element type QScopedPointer< SomeAbstractClass >. I could easily use something like this: QList
e3oroush
  • 3,045
  • 1
  • 17
  • 26
3
votes
1 answer

Pass QScopedPointer to function

How can I pass a QScopedPointer object to another function like that: bool addChild(QScopedPointer content){ TreeNode* node = new TreeNode(content); } TreeNode: TreeNode::TreeNode(QScopedPointer content) { …
yonutix
  • 1,964
  • 1
  • 22
  • 51
2
votes
1 answer

QScopedPointer Vs boost::scoped_ptr [which one to choose]

If I had an option to choose between QScopedPointer and boost::scoped_ptr, which one would do most good in the following cases: 1. QScopedPointer Vs boost::scoped_ptr 2. QScopedPointer Vs…
Chenna V
  • 10,185
  • 11
  • 77
  • 104
2
votes
0 answers

Qt: Debugger Crashes in qscopedpointer.h (application works though)

After recently converting my project over to make use Qt's opengl support (and thus using the Qt 5.4.0 MSVC2013 OpenGL 64bit Kit), I've been unable to properly debug because my application always 'crashes' at line 134 of qscopedpointer.h. I can run…
Yattabyte
  • 1,280
  • 14
  • 28
2
votes
1 answer

C2248 - No access to private member when passing QScopedPointer to function

I´m getting the following error on this piece of code. QScopedPointer onEvent(new NoteEvent(date, chan, pitch, vel, true)); QScopedPointer offEvent(new NoteEvent(date + dur, chan, pitch, vel,…
user2052244
  • 308
  • 3
  • 14
2
votes
3 answers

How to use QScopedPointer

I have an example that use QApplication app(argc,argv); QStandardItemModel* model = new QStandardItemModel(r,c,&app); But in my program I have QScopedPointer app(createApplication(argc, argv)); QStandardItemModel* model = new…
meolic
  • 1,177
  • 2
  • 15
  • 41
1
vote
1 answer

The use of sizeof in the implementation of QScopedPointer

To understand how Qt prevent incomplete type I went through the header file of qscopedpointer.h.The related part is as follows: template struct QScopedPointerDeleter { static inline void cleanup(T *pointer) { // Enforce…
Zhilei Han
  • 13
  • 4
1
vote
1 answer

QScopedPointer vs parent

I need some explanation about the next situation. Assume we have the next code: class MyClass : public QObject { public: MyClass(QObject* parent = nullptr) { m_member.reset(new QObject(this)); } ~MyClass(){} override; …
Polina Bodnar
  • 171
  • 3
  • 15
1
vote
1 answer

QScopedPointer with signals and slots

as the tittle says, i could not find any relationship or how to pass them to signals and slots. Anyone could give me a quick tutorial? or Introduction? :)
1
vote
2 answers

cannot convert 'QScopedPointer' to 'QStandardItem *'

I use this code without any error QStandardItem *newRow; newRow = new QStandardItem(hostname); model2->setItem(index, 2, newRow); I want to change the above code to the below: QScopedPointer newRow(new…
1
2