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
Contributor
developerUK
Posts: 35
Registered: ‎11-21-2012
My Device: 9810
My Carrier: o2
Accepted Solution

Webview - a few questions

I am using WebView and even cascades for the first time (I have learnt qt already) and I have a few questions.

 

How can I listen for the onURLChanged() signal - I have tried connecting to it's signal in cpp but my slot doesn't fire. could I call a function in my cpp code by stating it's name in qml?

 

I ask about qml because I think there is connecting of signals / slots in qml examples I have viewed (omitting the need for connect(mWebView, onUrlChanged(), this, myFunction()) but I can't see how I could connect say webview onUrlChanged(const QUrl &url) to myFunction(QUrl &myurl) which is in a .cpp file using the qml code rather than c++ . Is this possible?

 

Also, when I open a webpage using Webview and then reload the app I get a momentics error Cannot prepare and download the binary which means I have to restart dev alpha device - what should i be doing with webview in deconstructor to stop this restart requirement?

 

Thanks for any help you can offer.

Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Webview - a few questions

The signal is called urlChanged. Can you please paste C++ code where you tried to connect the signal? Signal names must be fully qualified (contain bb::cascades:: part) without argument names.

For QML you can create a signal handler:
onUrlChanged: {
// call C++ function here
}

C++ function should be marked as Q_INVOKABLE to be callable from QML and the object should be exported:

qml->setContextProperty("objName", &object);

Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Contributor
developerUK
Posts: 35
Registered: ‎11-21-2012
My Device: 9810
My Carrier: o2

Re: Webview - a few questions

Hi, thanks for your reply - sorry about my late reply.

 

I am trying to connect signal/slot using 

connect( mView, SIGNAL(bb::cascades::webview::urlChanged()) , this, SLOT(urlChangedSlot()) );

 

and I have tried

 

connect( mView, SIGNAL(bb::cascades::urlChanged()) , this, SLOT(urlChangedSlot()) );

 

But urlChangedSlot doesn't seem to get called when the webview is redirected to another url. 

 

I'm going to see what I can do with Q_Invokable functions.

Please use plain text.
Developer
Zmey
Posts: 1,510
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Webview - a few questions

I'm sorry, meant to say that parameter names should be fully qualified.

This one should work:

 

	QObject::connect(mView, SIGNAL(urlChanged(QUrl)),
	                 this, SLOT(urlChanged(QUrl)));

 

void ClassName::urlChanged(const QUrl& url)
{
  ...
}

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Contributor
developerUK
Posts: 35
Registered: ‎11-21-2012
My Device: 9810
My Carrier: o2

Re: Webview - a few questions

That did the trick.

 

Thanks a lot for your help.

Please use plain text.