C++ (Qt)#ifndef DOWNLOADER_H#define DOWNLOADER_H #include <memory>#include <QObject>#include <QString>#include <QNetworkReply>#include <QNetworkRequest>#include <QNetworkAccessManager> class Downloader : public QObject{public: Downloader( ) { m_manager = std::unique_ptr<QNetworkAccessManager>( new QNetworkAccessManager( this ) ); } void fetch( const QString &url ) { m_reply.reset( m_manager->get( QNetworkRequest( QUrl( url ) ) ) ); connect( m_reply.get( ), SIGNAL( finished( ) ), this, SLOT( replyFinished( ) ) ); } signals: void signalWithContent( QString content ); private slots: void replyFinished( ) { QByteArray data = m_reply->readAll( ); QString content( data ); emit signalWithContent( content ); } private: std::unique_ptr<QNetworkReply> m_reply; std::unique_ptr<QNetworkAccessManager> m_manager;}; #endif // DOWNLOADER_H
C++ (Qt)connect( m_reply.get( ), SIGNAL( fini ) );