QImgage pic( URL );
void MainWindow::paintEvent( QPaintEvent * event ){ if( firstpaint ) { listmanager->get( QNetworkRequest( QUrl( "http://........" ) ) ); firstpaint = false; }}
void MainWindow::finishedList( QNetworkReply * reply ){ if( reply->error() == QNetworkReply::NoError ) { forever { QByteArray byteline = reply->readLine(); if( byteline.size() == 0 ) break; urllist << byteline; // urllist это QStringList } foreach( QString url, urllist ) imgmanager->get( QNetworkRequest( url ) ) ); } else networkerror = true; reply->deleteLater();}
C++ (Qt)#include <QImage>#include <QNetworkAccessManager>#include <QNetworkRequest>#include <QNetworkReply>#include <QNetworkProxy> class UrlImage : public QObject, public QImage, public QNetworkRequest{ Q_OBJECTpublic: UrlImage( const QString& url, QObject* parent = 0 ) : QObject( parent ) , QNetworkRequest( url ) { QNetworkAccessManager am; // am.setProxy( QNetworkProxy( QNetworkProxy::HttpProxy, host, port ) ); QNetworkReply* reply = am.get( *this ); connect( reply, SIGNAL(finished()), this, SLOT(requestFinished()) ); QEventLoop loop; connect( reply, SIGNAL(finished()), &loop, SLOT(quit()) ); connect( reply, SIGNAL(error(QNetworkReply::NetworkError)), &loop, SLOT(quit()) ); loop.exec(); } private: UrlImage( const UrlImage& ) {} protected slots: void requestFinished() { QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); QString path( reply->url().path() ); QString suffix( path.mid( path.lastIndexOf( '.' ) + 1 ) ); QImage::load( reply, suffix.toLatin1().constData() ); reply->deleteLater(); }};
if( firstpaint ){ firstpaint = false; .....}