In my code
std::unique_ptr<QNetworkAccessManager> myNetworkAccessManager;
...
myNetworkAccessManager.reset(new QNetworkAccessManager(this));
QObject::connect(myNetworkAccessManager.get(), SIGNAL(finished(QNetworkReply *)), this, SLOT(OnNetworkFinished(QNetworkReply *)));
code in question: myNetworkAccessManager.get() in connect()
My question is what is the best way to do it?
I was reading the article here article where it says under Legacy Code:
Calling get() returns a pointer to the underlying method. You really want to avoid calling this if you can, because as soon as you release that raw pointer into the wild, you have lost much of the advantage you achieved by switching to unique_ptr
Update
If I changed it to use If I used QScopedPointer, my code would be as follows:
QScopedPointer<QNetworkAccessManager> myNetworkAccessManager;
...
myNetworkAccessManager.reset(new QNetworkAccessManager(this));
QObject::connect(myNetworkAccessManager.data(), SIGNAL(finished(QNetworkReply *)), this, SLOT(OnNetworkFinished(QNetworkReply *)));
would this be the correct solution then:
connect(myNetworkAccessManager.data()
Update 2
Reading this link stackoverflowit seems that using data() is the correct solution. Which mean that using get() from the stl is correct also.