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
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10
Accepted Solution

Cannot receive SIGNAL from webView.

 

I have a class that creates a webview in c++ and it is loaded in qml.  However, it can not receive any signals(for example loadingChanged) from webview

 

Here is the c++

BrowserLogin::BrowserLogin() {

    Container *rootContainer = Container::create();

    webView_ = new WebView();

    rootContainer->add(webView_);

    setRoot(rootContainer);

 

    connect(webView_, SIGNAL(navigationRequested(WebNavigationRequest*)),this,SLOT(navigationRequested(WebNavigationRequest*)));

    connect(webView_, SIGNAL(loadingChanged(WebLoadRequest*)),this,SLOT(loadingChanged (WebLoadRequest*)));

}

 

QString BrowserLogin::url() {

returnurl_;

}

 

void BrowserLogin::setUrl(QString url) {

url_ = url;

if (!url_.isEmpty()) {

webView_->setUrl(url_);

}

}

 

void BrowserLogin::navigationRequested (WebNavigationRequest *request) {

}

 

void BrowserLogin::loadingChanged (bb::cascades::WebLoadRequest *loadRequest) {

}

 

And QML

import bb.cascades 1.0

 

import browser.login.lib 1.0

 

Page {

    property string myUrl: "http://www.google.com"

 

    Container {

        

        layout: DockLayout {

        }

 

        ScrollView {

 

            scrollViewProperties {

                scrollMode: ScrollMode.Vertical

            }

 

            BrowserLogin {

                url: gasUrl

            }

 

        }

    }

}

 

It loads the webpage and shows in the scrollView properly, but just not get any SIGNAL from webview.

 

Thanks for any advice.

 

Tyler

 

Please use plain text.
Developer
DrShavargo
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10

Re: Cannot receive SIGNAL from webView.

The below method will allow you to recieve signals in c++ from qml elements (such as webview). This may not be exact, so please look into it.

 

In your QML:

 

onLoadingChanged:{
    app.loadingChanged();
}

 In your C++:

 

BrowserLogin::BrowserLogin(){
root->setContext(app, "app") //Or whatever it is...
}

void BrowserLogin::loadingChanged(-){
    // your code here
}

In your .hpp:

 

Q_INVOKABLE void loadingChanged(-)
----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Please use plain text.
Contributor
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10

Re: Cannot receive SIGNAL from webView.

Thanks.  The reason I took the current approach is that I want to take more control of the webview, such implement its own cookie manager and check the header before loading the page.  I found some of method such as clear the cookies is only avaialbe in C++.  I cannot do the same thing in QML.

 

The fundamental issue I have now is that when insert a c++ object in QML, the object couldn't received SIGNAL properly.  This usually works when I create and load the object in c++.

Please use plain text.
Developer
DrShavargo
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10

Re: Cannot receive SIGNAL from webView.

[ Edited ]

I see your problem, and although I'm not sure know how to fix it, I can offer a workaround. You could always create it in QML, use the code I posted, and then find it in C++ with a findChild() method, such as:

 

QObject *object = root->findchild<QObject*>("objectName")

Then, from c++, you can get and set most properties and recieve any calls it maked by adding on"Whatever" to the qml from your c++ code. Implementing cookies and checking the header will then be done through that QObject. I would suggest trying to find a solution tailored to your problem before attempting this, cause it's quite a change in code.

 

Edit: Also, look into WebStorage and WebCookieJar for all your cookie clearing needs.

 

Edit #2: Found this in the WebView API:

 

onNavigationRequested: {
    console.log("NavigationRequested: " + request.url + " navigationType=" + request.navigationType)
    if (shouldAcceptNavigationToUrl(request.url)) {
        request.action = WebNavigationRequestAction.Accept
    } else {
        request.action = WebNavigationRequestAction.Ignore
    }
}

 

onLoadingChanged: {
    if (loadRequest.status == WebLoadStatus.Started) {
        statusLabel.setText("Load started.")
    }
    else if (loadRequest.status == WebLoadStatus.Succeeded) {
        statusLabel.setText("Load finished.")
    }
    else if (loadRequest.status == WebLoadStatus.Failed) {
        statusLabel.setText("Load failed.")
    }
}

 Dunno if it will help, but you can connext to c++ the exact same way as before through these calls.

 

 

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Please use plain text.
Contributor
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10

Re: Cannot receive SIGNAL from webView.

Thanks,  That could be a decent solution.

 

I figured out the webview signal issue.  I miseds the full qualified type in the connect call, it should be 

bb::cascades::WebNavigationRequest* instead.

 

Another developer actually had the same issue before.

 

http://supportforums.blackberry.com/t5/Cascades-Development/Cannot-connect-to-WebView-loadingChanged...

 

Many thanks again.

Please use plain text.
Developer
DrShavargo
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10

Re: Cannot receive SIGNAL from website.

Glad you caught that, cause i completly missed it, and as always thanks for marking the thread as solved.

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Please use plain text.