0

URLとして設定imageSourceするには?ImageView

   ImageView {
               imageSource: "http://myrrix.com/wp-content/uploads/2012/06/stackoverflow.png"
             }

enter code hereこれは機能していません。ImageView で画像を「asset: ///images/myimage.png」としてしか設定できません。ソースを URL から設定する方法は?

4

1 に答える 1

4

You can not directly load image from web. You need to make a network request using QNetworkRequest, QNetworkAccessManager, and QNetworkReply classes & on getting reply load that QByteArray in ImageView.

QNetworkAccessManager* netManager = new QNetworkAccessManager();
if (netManager) {
    QUrl url(ImageUrl);
    QNetworkRequest networkRequest(url);
    QNetworkReply* networkReply = netManager->get(networkRequest);
    connect(networkReply, SIGNAL(finished()), this, SLOT(onReply()));
}

& in onReply() slot you can load image:

void App::onReply(QNetworkReply* reply) {
    if (reply->error() != QNetworkReply::NoError) {
        qDebug() << "Image not available or any error";
        return;
    }
    Image image = Image(reply->readAll());
    imageView->setImage(image);
}    
于 2013-01-31T09:23:32.967 に答える