在ImageView BlackBerry上设置图像源 [英] Set Image Source on ImageView BlackBerry
本文介绍了在ImageView BlackBerry上设置图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在ImageView
上将imageSource
设置为URL?
How to set imageSource
on ImageView
as url?
ImageView {
imageSource: "http://myrrix.com/wp-content/uploads/2012/06/stackoverflow.png"
}
这不起作用,我只能在ImageView上将图像设置为"asset:enter code here
///images/myimage.png".如何将来源设置为来自URL?
This is not working, I can only set the image as "asset:enter code here
///images/myimage.png" on the ImageView. How to set the source to be from URL?
推荐答案
您不能直接从Web加载图像.您需要使用QNetworkRequest,QNetworkAccessManager和QNetworkReply类&获得回复时,将QByteArray加载到ImageView中.
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()));
}
&在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);
}
这篇关于在ImageView BlackBerry上设置图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文