PDA

View Full Version : QObject explicit constructing and QSharedData



kornicameister
12th March 2013, 08:13
Hi,
I want to create the class which extends QObject and support QSharedData. However I am given with the compiler warning as
follow:

ostrzeżenie:base class 'class QObject' should be explicitly initialized in the copy constructor [-Wextra].

Therefore I am thinking of this approach being valid or invalid, because my intention is to have the class which can be initialized with parent from any other class but with QSharedData support. How can I get this without causing compiler to complain ?

anda_skoa
12th March 2013, 19:03
It would help to see the class header and source.

Cheers,
_

kornicameister
12th March 2013, 19:23
class QubiconModelData;
class QubiconModel : public QObject {
public:
QubiconModel();
QubiconModel(const QubiconModel &);
QubiconModel &operator=(const QubiconModel &);
~QubiconModel();

private:
QExplicitlySharedDataPointer<QubiconModelData> data;
};

here is the header...I didn't wrote it myself, this particular part of code has been auto-generated via QtCreator new class wizard.

wysota
12th March 2013, 21:30
It won't work. QObject instances can't be copied. Why do you want to derive that class from QObject?

kornicameister
12th March 2013, 23:06
Wanted to have out-of-the-box support for automatic objects deallocation...however it seems that since it is not possible I will just take care of it myself :p

wysota
12th March 2013, 23:17
Wanted to have out-of-the-box support for automatic objects deallocation..

I don't see how that's related. If you have a value-based class that contains a shared data pointer then you allocate such objects on the stack and you don't need any special automatic object deallocation because deallocation is automatic by the definition. If you allocate such objects on the heap, then you usually don't need them to be based around shared data and even if you do, you can use an external smart pointer to manage such object.

kornicameister
12th March 2013, 23:32
That's some useful explanation...thank you :)