在ImageView BlackBerry上设置图像源

时间:2013-01-31 09:14:22

标签: qml blackberry-10

如何将imageSource上的ImageView设置为网址?

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

这不起作用,我只能在ImageView上将图像设置为“asset:enter code here /// images / myimage.png”。如何将来源设置为来自URL?

1 个答案:

答案 0 :(得分:4)

您无法直接从网络加载图片。您需要使用QNetworkRequest,QNetworkAccessManager和QNetworkReply类来生成网络请求。获取回复加载ImageView中的QByteArray。

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

&安培;在onReply()插槽中,您可以加载图像:

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);
}