关于QSharedPointer
在以下场景中使用的一个问题:
我有一个有两个QSharedPointer
s 私人班级成员的班级:
class xy{
...
private:
QSharedPointer<QNetworkAccessManager> m_nam;
QSharedPointer<QNetworkReply> m_nr;
};
在我发送QNetworkAccessManager
帖子的代码中,返回值是一个QNetworkReply
指针。
QNetworkReply * QNetworkAccessManager::post(const QNetworkRequest & request, const QByteArray & data)
我想将此指针传递给我的QSharedPointer
ie m_nr
。我试过了:
m_nam.reset( new QNetworkAccessManager(m_parent.data()));
QNetworkRequest request(url);
...
...
// following line is my problem
m_nr = QSharedPointer<QNetworkReply>(m_nam->post(request, postData));
...
但是崩溃了,然后我尝试了:
m_nam.reset( new QNetworkAccessManager(m_parent.data()));
QNetworkRequest request(url);
...
...
// following line is my problem
m_nr.reset( m_nam->post(request, postData));
...
但也崩溃了。
如何将QNetworkReply
指针正确传递给我的QSharedPointer
?