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
Developer
Brennan12325
Posts: 205
Registered: ‎05-15-2012
My Device: None

Re: With the folRe: Problems with Webview

[ Edited ]

I use WebView with only small amounts of issues, haha. It crashes the emulator because the WebView leaks memory like a sieve, but I think that's just an emulator issue. I have no device to test it on.

 

Here's some of my code:

 

	m_ContentContainer = new Container(parent);
	if(!App::IsDarkTheme())
	{
		m_ContentContainer->setBackground(Color::DarkGray);
	}
	m_ContentContainer->setPreferredSize(768.0f, 1280.0f);

 

 

	else
	{
		//m_Title = new TextArea();
		//m_Title->setEditable(false);
		//m_Title->setText(title);

		if(url.isValid())
		{
			m_WebProgressIndicator = new ProgressIndicator();
			m_WebProgressIndicator->setToValue(100.0f);
			m_WebProgressIndicator->setFromValue(0.0f);
			m_WebProgressIndicator->setValue(0.0f);
			m_WebProgressIndicator->setHorizontalAlignment(HorizontalAlignment::Center);

			m_WebContent = new WebView();
			m_WebContent->setHorizontalAlignment(HorizontalAlignment::Center);
			m_WebContent->setUrl(url);

			//connect(
			//	m_WebContent,
			//	SIGNAL(navigationRequested(bb::cascades::WebNavigationRequest*)),
			//	SLOT(killNavigation(bb::cascades::WebNavigationRequest*)));

			connect(m_WebContent, SIGNAL(loadProgressChanged ( int )),
					this, SLOT(updateProgress ( int )));
		}

		m_ScrollView = ScrollView::create(m_WebContent)
			.scrollMode(ScrollMode::Both)
			.pinchToZoomEnabled(true)
			.maxContentScale(5.0f)
			.minContentScale(1.0f)
			.preferredSize(768.0f, 1280.0f);;

		//m_ContentContainer->add(m_Title);
		m_ContentContainer->insert(0,m_WebProgressIndicator);
		m_ContentContainer->insert(0,m_ScrollView);
	}

 

Notably my webview is within a scrollview, but it really shouldn't make a difference either way.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Developer
p8
Posts: 132
Registered: ‎01-24-2013
My Device: blackberry z10

Re: Problems with Webview

I built the Cascades Cookbook app, which contains a "WebRecipe" , ie when you chose the "WebView" listitem it opens a webview in a new page. This project seemed to run consistently for me, and I could interact with the webview (ie click on links and get the webview to navigate as expected) without it crashing.

  which puzzled me, so I created a new  cascades project using the Wizard from the "empty" template.

 

I called the Project "Tst" and it created a main.cpp, a Tst.hpp and a Tst.cpp for me.

I then copied the webviewrecipe.h and .cpp files into my project.

Then I edited the Tst.cpp and main.cpp files so that they look like below.

 

I built using a Device-Debug config for my Blackberry 10 dev alpha, and my sdk 10.0.10.263 (which is also on the device). When I ran the project from the (Momentics) IDE, it sometimes ran without on crahsing on the device. Usually if clicking one link worked the app worked fine from then on. On some runs it crashed and always on the first link I clicked on.

 

If I ran the project nby clicking the icon on the device (ie independently of the IDE) it always crashed.

If I debug the project from the IDE I get the console output

"Cannot access memory at address 0x29c" and mention of a segmentation fault.

 

So I guess this really is a bug (unless anyone can see something silly Im doing?), and the webview working in the CppCookbook and my Qml version was more coincidence (memory occupied in such a way that the stray pointer didnt do any damage?)

 

//-----------------------------------------

//------------main.cpp---------------

//-----------------------------------------

// Default empty project template
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <QLocale>
#include <QTranslator>
#include <Qt/qdeclarativedebug.h>

#include "Tst.hpp"

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    // this is where the server is started etc
    Application app(argc, argv);

    new Tst(&app);

    // we complete the transaction started in the app constructor and start the client event loop here
    return Application::exec();
    // when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
}

//-----------------------------------------

//------------Tst.cpp-------------------

//-----------------------------------------

// Default empty project template
#include "Tst.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <bb/cascades/Page>
#include <bb/cascades/Container>
#include "webviewrecipe.h"

using namespace bb::cascades;

Tst::Tst(bb::cascades::Application *app)
: QObject(app)
{
    Page *Pg = new Page();
    Container *Cont = new Container();

    WebViewRecipe * Wr = new WebViewRecipe(Cont);
    Pg->setContent(Cont);
    app->setScene(Pg);
}

 

Developer
Developer
p8
Posts: 132
Registered: ‎01-24-2013
My Device: blackberry z10

Re: Problems with Webview