Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Contributor
Posts: 15
Registered: ‎02-28-2012
My Device: Dev Alpha A
My Carrier: Koodo
Accepted Solution

webview URL loading in C++

I have a webview and url property defined in QML as follow:

WebView {
 id: mWebView
 objectName: "mWebView"
 url: "http://www.google.com"
}

 

I then try to load a different URL in C++ as follow:

 

mImageView = root->findChild<ImageView*>("mImageView");

mWebView->setUrl(QUrl("http://www.yahoo.com"));

mWebView->reload();

 

I can tell webview object did refresh because of the reload command but showing google.com instead yahoo.  Is this the right way to load a new URL to an existing webview object?

Developer
Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified

Re: webview URL loading in C++

Hello,

 

   As per your code there are diffrenet object name into Qml and Cpp.

 

   You try antoher url insted off "http://www.yahoo.com".Please check below code.

 

    Qml

import bb.cascades 1.0

Page {
    content: Container {
        WebView {
            id: mWebView
            objectName: "mWebView"
            url: "http://www.google.com"
        }
    }
}

  Cpp 

 

   

#include "app.hpp"
#include "c_ListView.h"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Page>
#include <bb/cascades/Button>
#include <bb/cascades/WebView>

using namespace bb::cascades;

App::App() {
	QmlDocument *qml = QmlDocument::create("web_view.qml");

	Page* page = qml->createRootNode<Page>();

	WebView *bmImageView = page->findChild<WebView*>("mWebView");

	bmImageView->setUrl(QUrl("http://blackberry.com"));
	bmImageView->reload();

	Application::setScene(page);
}

 

----------------------------------------------------------------------------------------------------------------------------------

feel free to press the like button on the right side to thank the user that helped you.

   

Contributor
Posts: 15
Registered: ‎02-28-2012
My Device: Dev Alpha A
My Carrier: Koodo

Re: webview URL loading in C++

My bad.  That was a copy and paste error.  The object name is correct as I mentioned that doing a reload via cpp does have an effect on the WebView object.

 

I find that if url property is not set or define in qml then setUrl call in cpp on webview object will work but only once.

Developer
Posts: 692
Registered: ‎08-09-2010
My Device: Not Specified

Re: webview URL loading in C++

I find that if url property is not set or define in qml then setUrl call in cpp on webview object will work but only once

 

>>>>>>

 

I can't undestand please provide me full flow.

 

Thanks.

Contributor
Posts: 15
Registered: ‎02-28-2012
My Device: Dev Alpha A
My Carrier: Koodo

Re: webview URL loading in C++

Ok. It turns out that all I need to load a new page is to call WebView's setUrl function. The reload call that follows immediately is actually cancelling the loading of the new page.

 

mWebView->setUrl(QUrl("http://www.yahoo.com"));

//mWebView->reload();

Contributor
Posts: 15
Registered: ‎11-30-2010
My Device: Blackberry Storm 9550
My Carrier: A T & T

Re: webview URL loading in C++

Is there any way to create and use a WebView widget with a C/C++ app?  Is it necessary to set up the WebView object in QML first? 

 

Thanks

 

jvstewart