PDA

View Full Version : initilization of QScopedPointer



weaver4
8th April 2014, 15:32
I have a empty QScopedPointer defined in a header.


QScopedPointer<HardwareInterface> hwi;


I know that I can initilize it doing this in my class.


MainClass::MainClass(QObject *parent) :
QObject(parent), hwi(new HardwareInterface())
{
}


But is there another way to do it in the main-line of the code? For example maybe I need to get the values of parameters before I init it.

I have tried this,


hwi = QScopedPointer<HardwareInterface>(new HardwareInterface());


but I get this error:



/home/trey/Qt5.2.1/5.2.1/gcc_64/include/QtCore/qglobal.h:979: error: 'QScopedPointer<T, Cleanup>& QScopedPointer<T, Cleanup>::operator=(const QScopedPointer<T, Cleanup>&) [with T = HardwareInterface; Cleanup = QScopedPointerDeleter<HardwareInterface>]' is private
Class &operator=(const Class &) Q_DECL_EQ_DELETE;
^


whatever that means.

Infinity
8th April 2014, 16:13
You can set the pointer after initialization using the reset method.

anda_skoa
8th April 2014, 17:39
Or use a QSharedPointer.

Cheers,
_

weaver4
8th April 2014, 20:11
thanks!

I guess I should of looked for something that took a pointer and returned a QScopedPointer.