PDA

View Full Version : Using std::shared_ptr for Qt objects



8Observer8
18th June 2014, 15:58
Hello!

Please, help me to solve this problem:



DownLoader.h:19: error: no matching function for call to 'Downloader::connect(std::shared_ptr<QNetworkReply>&, const char*, Downloader* const, const char*)'
* * * * * * * * *this, SLOT(replyFinished( ) ) );




#ifndef DOWNLOADER_H
#define DOWNLOADER_H

#include <memory>

#include <QObject>
#include <QString>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetWorkAccessManager>

class Downloader : public QObject
{
* *Q_OBJECT

* *Downloader( )
* *{
* * * *connect( m_reply, SIGNAL( finished( ) ),
* * * * * * * * this, SLOT( replyFinished( ) ) );
* *}

* *void fetch( const QString &url )
* *{
* * * *m_reply.reset(m_manager->get( QNetworkRequest( QUrl( url ) ) ) );
* *}

signals:
* *void signalWithContent( QString * );

private slots:
* *void replyFinished( )
* *{
* * * *QByteArray data = m_reply->readAll( );
* * * *QString content( data );
* * * *emit signalWithContent( &content );
* *}

private:
* *std::shared_ptr<QNetworkAccessManager> m_manager =
* * * * * *std::make_shared<QNetworkAccessManager>( new QNetworkAccessManager( this ) );

* *std::shared_ptr<QNetworkReply> m_reply;
};

#endif // DOWNLOADER_H

thomas@itest
18th June 2014, 16:15
QObject::connect(m_reply.get(),SIGNAL(finished()), this,SLOT(replyFinished());
(m_reply is NOT a QObject)

8Observer8
18th June 2014, 17:02
Thank you very much! :) http://www.cplusplus.com/reference/memory/shared_ptr/get/