简体   繁体   English

如何在Blackberry Cascades,QML和C ++,QT的列表视图中获取Web视图

[英]How do I get a web view in a list view in Blackberry Cascades, QML & C++, QT

I am trying to get a list of images from the internet to show up in a list view in QML. 我试图从互联网上获取一个图像列表,以便在QML的列表视图中显示。 I have code that looks like this: 我的代码看起来像这样:

ListView {

    objectName: "imageListView"

    listItemComponents: [

        ListItemComponent {

            type: "item"

            Container {
                WebView {
                     url: ListItemData.imageSource
                }    
            }                           
        }
    ]
}

The problem is this just causes the following error: "Unable to assign [undefined] to QUrl url" 问题是这只会导致以下错误:“无法将[undefined]分配给QUrl url”

I know the ListItemData.imageSource contains the correct data, because I tested it using, Label { text: ListItemData.imageSource }, in place of the WebView, and it showed all the image urls that are needed. 我知道ListItemData.imageSource包含正确的数据,因为我使用Label {text:ListItemData.imageSource}来测试它,代替了WebView,它显示了所需的所有图像URL。

I would suggest you to use ImageView only even if you are loading images from internet. 我建议你只使用ImageView,即使你是从互联网上加载图像。

First of all, make a network request using QNetworkRequest, QNetworkAccessManager, and QNetworkReply classes & on getting reply load that QByteArray in ImageView. 首先,使用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()));
}

& in onReply() slot you can load image like this: 在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);

}

Do note that if the image is too large, you may have to ImageData class & its method to load image in cascade ImageView. 请注意,如果图像太大,您可能必须使用ImageData类及其方法在级联ImageView中加载图像。 It won't load image directly by using setImage method. 它不会使用setImage方法直接加载图像。 & to make this work with ListView, you have to create your own CustomItem & ListItemProvider & also have to override update item method of that. 要使用ListView,你必须创建自己的CustomItem和ListItemProvider,并且还必须覆盖它的更新项方法。 Hope this helps. 希望这可以帮助。

Ok - so I found another solution. 好的 - 所以我找到了另一个解决方案 I upgraded from the Beta 2 SDK to the Beta 3 SDK. 我从Beta 2 SDK升级到Beta 3 SDK。 Then I simply did something like this: 然后我简单地做了这样的事情:

#include <QObject>
#include <bb/cascades/Image>

class MyImageClass : public QObject, public bb::cascades::Image
{
    Q_OBJECT

    Q_PROPERTY(bb::cascades::Image image READ image WRITE setImage NOTIFY imageChanged FINAL)

    //...
    bb::cascades::Image image_;
public:
    //...
    bb::cascades::Image image() const {return image_;}

    void setImage(bb::cascades::Image image {
         image_ = image;
         emit imageChanged();
    }

signals:
    //...
    void imageSourceChanged();
}

Then when inserting an image into the list, I simply used: 然后在将图像插入列表时,我只是使用:

groupDataModel_.insert(myImageObject);

and in my qml I have: 在我的qml我有:

ListView {
    id: imageListView
objectName: "ImageListView"         

    listItemComponents: [
    ListItemComponent {
        type: "item"

        Container {
            id: imagesRoot
            objectName: "ImagesRoot"

                ImageView {
                image: ListItemData.image
            }
        }
    }
    ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何响应在Blackberry 10 Cascades中的qml,C ++ qt列表视图中单击列表项 - How to respond to clicking on list items in a list view in qml, C++ qt, in Blackberry 10 Cascades 在Blackberry Cascades 10(C ++,Qt,QML)中,如何调用填充了字段的电子邮件客户端? - In Blackberry Cascades 10 (C++, Qt, QML), how do I invoke an email client with the fields populated? 如何使用Cascades,Blackberry 10中的Qt / QML / C ++从另一个qml文件更改一个qml文件中的标签文本? - How do I change the label text in one qml file from another qml file using Qt/QML/C++ in Cascades, Blackberry 10? Blackberry 10 Cascades qml(C ++和QT)中的布局存在问题 - Having an issue with the layouts in Blackberry 10 Cascades, qml (C++ & QT) 如何在Blackberry Cascades QML和QT中点击列表项组件 - How to tap on a list item component in Blackberry Cascades qml and qt 尝试将QGeoSearchReply的结果添加到Blackberry 10级联(C ++,QT和QML)中的maps :: DataProvider中 - Trying to add the result of a QGeoSearchReply to a maps::DataProvider in Blackberry 10 Cascades (C++, QT & QML) 我的Blackberry 10 Cascades(C ++,Qt和QML)示例应用程序在启动时崩溃,并出现以下错误 - My Blackberry 10 Cascades (C++, Qt & QML) sample app is crashing on startup with the following error 如何在C++、Qt、QML、Blackberry 10 Cascades Beta 3 SDK中制作图表/图形(如折线图、条形图、圆形图)等? - How to make charts/graphs (such as line graphs, bar graphs, circle graphs), etc. in C++, Qt, QML, Blackberry 10 Cascades Beta 3 SDK? 试图用Blackberry Cascades QT和QML下载图像 - Attempting to download an image in Blackberry Cascades QT, and QML 使XML数据在C ++的Blackberry 10 Cascades QML中的listItemComponents中显示 - Make XML data show in listItemComponents in Blackberry 10 Cascades QML from C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM