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

Web and WebWorks Development

Reply
Highlighted
Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Slot is not getting called in BB 10 Native extension

Hi,

 

I am implementing native extension using CellularDataInterface API. Not getting any error at runtime but slot is not getting called. Below is the code:

 

boolean isConnected = QObject::connect(_cellularDataInterface, SIGNAL(connectionStateChanged(bb::device::CellularConnectionState::Type)),
				this, SLOT(connectionStateChanged(bb::device::CellularConnectionState::Type)));

 

isConnected is returning false(0).

 

After calling connectService, connectionStateChanged is not getting called.

 

void DeviceInfo::connectService() {

	_cellularDataInterface->setName("blackberry");
	if (_cellularDataInterface->isValid()) {
		_cellularDataInterface->requestConnect();



	} else {
		QString jsonStr = "Name is invalid";
		processResponse(jsonStr.toLocal8Bit().data());
	}
}

 

 

 

void DeviceInfo::connectionStateChanged (bb::device::CellularConnectionState::Type connectionState)
{
	QString jsonStr = "Connected!!!";
	processResponse(jsonStr.toLocal8Bit().data());

	if (connectionState == CellularConnectionState::Connected) {

		int EOK = 0;
	    if (setenv("SOCK_SO_BINDTODEVICE", _cellularDataInterface->networkInterfaceName().toAscii().constData(), 1) == EOK) {
	    	QNetworkRequest request = QNetworkRequest();
	    	request.setUrl(QUrl("http://www.blackberry.com"));
	    	_networkAccessManager->get(request);

	    } else {
	    	QString jsonStr = "Unable to set SOCK_SO_BINDTODEVICE";
	    	processResponse(jsonStr.toLocal8Bit().data());

	    }

	} else if (connectionState == CellularConnectionState::PendingConnect) {
		QString jsonStr = "Pending Connect";
		processResponse(jsonStr.toLocal8Bit().data());

	} else if (connectionState == CellularConnectionState::Disconnected) {
		 QString jsonStr = "Disconnected";
		 processResponse(jsonStr.toLocal8Bit().data());
	    unsetenv("SOCK_SO_BINDTODEVICE");


	} else {
		 QString jsonStr = "Unrecognised state";
		 processResponse(jsonStr.toLocal8Bit().data());
	}
}

 

To verify it, I created a Sample application and this code is working fine there.

But in extension, facing issues.

 

Please Help. It's very urgent.

Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Re: Slot is not getting called in BB 10 Native extension

Still slot is not working. please let me know what can be the reason that slot is not connecting and returning false.
Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: Slot is not getting called in BB 10 Native extension

It's not so simple. I think support for Qt signals and slots in WebWorks and Phonegap/Cordova is a work-in-progress:

 

https://github.com/blackberry/WebWorks-Community-APIs/issues/166

https://github.com/blackberry/WebWorks-Community-APIs/issues/194

 

Unfinished sample: https://github.com/haahmad/SignalSlotExample

 

The template mentioned is here but I can't seem to locate any signal/slot support:

https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10-Cordova

 

Here's another thread discussing the issue:

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Connecting-QObjects-in-a-webwork...

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Re: Slot is not getting called in BB 10 Native extension

Thanks for reply.
Does it mean that signal and slot mechanism is not possible till now while implementing native extensions?
Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: Slot is not getting called in BB 10 Native extension

I'm not sure. It's probably technically possible if you have the right expertise, but it's not documented anywhere, nor do there seem to be any samples.

 

I would expect to encounter some tricky problems with library initialization, threading and the Qt event loop, as the WebWorks runtime/browser has its own event loop of course.

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Re: Slot is not getting called in BB 10 Native extension

I tried to implement the javascript part of sample native extension given at below link:

https://github.com/haahmad/SignalSlotExample

 

My javaScript part for above extension is below:

 

Client.js:

var _self = {}, _ID = require("./manifest.json").namespace; // These methods are called by your App's JavaScript // They make WebWorks function calls to the methods // in the index.js of the Extension //get Connection status _self.start = function (callback) { window.webworks.event.once(_ID, "signalCaught!", callback); return window.webworks.execAsync(_ID, "start", null); }; module.exports = _self;

 

index.js:

var template = require("./templateJNEXT").template, _event = require("../../lib/event"), _utils = require("../../lib/utils"); module.exports = { start: function (success, fail) { // args = JSON.parse(decodeURIComponent(args["input"])); template.getInstance().start(); success(); } };

 

templateJNEXT.js:

var template, _event = require("../../lib/event"); JNEXT.Template = function () { var self = this, hasInstance = false; self.getId = function () { return self.m_id; }; self.init = function () { if (!JNEXT.require("libSignalSlot")) { return false; } self.m_id = JNEXT.createObject("libSignalSlot.SignalSlot"); if (self.m_id === "") { return false; } JNEXT.registerEvents(self); }; // Fired by the Event framework (used by asynchronous callbacks) self.onEvent = function (strData) { var arData = strData.split(" "), strEventDesc = arData[0], jsonData; // Event names are set in native code when fired, // and must be checked here. if (strEventDesc === "signalCaught!") { // Slice off the event name and the rest of the data is our JSON //jsonData = arData.slice(1, arData.length).join(" "); _event.trigger("signalCaught!", JSON.parse(jsonData)); } }; // ************************ // Enter your methods here // ************************ // calls into InvokeMethod(string command) in template_js.cpp self.start = function (input) { return JNEXT.invoke(self.m_id, "start");//+ input/*JSON.stringify(input)*/ }; // ************************ // End of methods to edit // ************************ self.m_id = ""; self.getInstance = function () { if (!hasInstance) { hasInstance = true; self.init(); } return self; }; }; template = new JNEXT.Template(); module.exports = { template: template };

 

index.html:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link href="css/styles.css" rel="stylesheet" type="text/css"> <title>DeviceInfo Extension Test</title> <script type="text/javascript" src="local:///chrome/webworks.js"></script> </head> <body> <script type="text/javascript"> var rippleLoaded = false; document.addEventListener('webworksready', function(e) { // This is a hack for Ripple calling webworksready multiple times if (rippleLoaded) return; rippleLoaded = true; update(); }, false); function update() { if (rippleLoaded && community.signalslot) { div = document.getElementById('connect'); div.innerHTML = 'BB 10.2 : Connection Status is: ' + community.signalslot.start(function(data){ if (data){ console.log(data); alert('callback recieved'+data); }else{ alert('callback recieved in else'); } }); div.className = 'invoked'; } } </script> <div id='connect' class='notInvoked'>Service not connected</div> </body> </html>

 

config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<widget xmlns="http://www.w3.org/ns/widgets" 
        xmlns:rim="http://www.blackberry.com/ns/widgets" 
        version="1.0.0" id="community.deviceinfo.test" xml:lang="en">
	
	<name>SignalSlot Test</name>
	<description>Test App for the DeviceInfo Extension</description>
	<author>canvasm</author>
	
	<rim:orientation mode="auto" />
	
	<content src="index.html"/>
	
	<feature id="community.signalslot" />
	
	<access subdomains="true" uri="*"/>
	
	<rim:permissions>
		<rim:permit>read_cellular_data</rim:permit>
		<rim:permit>access_internet</rim:permit>
		<rim:permit>read_device_identifying_information</rim:permit>
	</rim:permissions>


</widget>

 

But alert in callback mentioned in index.html is not coming. 

 

 

As per R&D, i found that there is no easy way to debug the extension code. But still I tried to debug the code by putting logs. But no logs are generated in web inspector. 

 

Please help me to find the solution of problem. It's very urgent.

Thanks in advance Smiley Happy

 

 

 

Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Re: Slot is not getting called in BB 10 Native extension

I tried to include Q_OBJECT in my extension and when run on device. it shows ".so file not found" error.

I tried with many libraries but no success.

 

 

bb101.png

 

 

bb10.png

 

What library should i include to resolve ".so file not found" error for Q_OBJECT.

 

Also please let me know the procedure to generate moc file.

 

 

 

BlackBerry Development Advisor
Posts: 841
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Slot is not getting called in BB 10 Native extension

Q_OBJECT is not in a library - It's a macro for Qt. The sample assumes you know how to generate a .moc file and that's what you need to do so that all those macros (Q_OBJECT, SIGNAL, SLOT, etc) get converted into the actual code that is needed.

 

I understant that you are probably working to a tight deadline and need this urgently, but you've gone completely out into an area where there is no official support, no documentation, and only small numbers of people anywhere who have the necessary background to know what to do, let alone teach you all the necessary background so you are an expert as well. I'm concerned that going down this route may be a lot more trouble for you than it's worth given where the support is at today.

 

In the majority of cases, using Signals and Slots, or even Qt classes is not necessary for an extension. What is the capability that you're trying to use? It's quite possible that there's another way that is more proven and supportable.

Tim Windsor
Open Source Technical Lead
BlackBerry Development Advisor
Posts: 841
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Slot is not getting called in BB 10 Native extension

That said, maybe you're already 99% of the way there.

 

Did you see the readme on the SignalSlot demo project?

https://github.com/haahmad/SignalSlotExample/blob/master/README.md

 

It has a command line for running moc. I have no idea what the parameters are or what to do with the results, but it's part of the way Qt works, so searching on Google is likely to get you some results.

Tim Windsor
Open Source Technical Lead
Developer
Posts: 101
Registered: ‎03-15-2011
My Device: Blackberry 9800
My Carrier: developer

Re: Slot is not getting called in BB 10 Native extension

Thanks Tim Windsor, for your prompt reply.

 

To run moc command, 

 

I copied two files(SignalHandler.cpp & SignalHandler.hpp) containing signal and slot at below path:

BB10_SDK_PATH/host_10_0_9_404\win32\x86\usr\bin

 

And run the command:

 

BB10_SDK_PATH\host_10_0_9_404\win32\x86\usr\bin> moc -o SignalHandler.cpp SignalHandler.hpp

 

It is neither showing error nor generating any file.

 

I referred Writing Make Rules for Invoking moc section of below link also:

http://qt-project.org/doc/qt-4.8/moc.html

 

But not getting how to make rules.

 

In Limitations section on same link, it is written that "moc does not handle all of C++. The main problem is that class templates cannot have signals or slots.

 

Does it mean that we can not create moc files for for the classes containing signals and slots?

 

Please Help!!