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
New Contributor
JonathanLennox
Posts: 5
Registered: ‎03-28-2013
My Device: BlackBerry 10 Dev Alpha

Not getting screen events from Qt event filter

Hi -- my Qt/Cascades application is wrapping a native (OpenGL) window which wants to be able to respond to screen events on its own, so I'm installing an event filter using QAbstractEventDispatcher::instance()->setEventFilter, following the advice in <http://qt-project.org/wiki/BPS_Events_and_Qt>.

 

Unfortunately, while my event filter receives navigator events, it doesn't receive any screen events.  Clearly Qt is receiving screen events, since it's acting upon screen touches, but for some reason my event filter doesn't receive them.

 

Are screen events perhaps received on a different thread?  If so, how do I get access to that other thread to install a filter into its event dispatcher?

 

I'm running OS 10.0.10.263.

 

Here's my code.  For testing, I added my filter code to main.cpp in the Cascades sample app HelloForeignWindow.

 



#include "helloforeignwindowapp.h"

#include <bps/bps.h>
#include <bps/screen.h>
#include <bps/navigator.h>
#include <screen/screen.h>
#include <QAbstractEventDispatcher>

using ::bb::cascades::Application;

static QAbstractEventDispatcher::EventFilter previousEventFilter = NULL;


bool EventReceived(bps_event_t* event)
{
	int domain = bps_event_get_domain(event);
	int code = bps_event_get_code(event);
	if (domain == screen_get_domain()) {
	    screen_event_t screen_event = screen_event_get_event(event);
	    int event_type;
	    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type);
	    fprintf(stderr, "Screen event type %d received in filter\n", event_type);
	}
	else if (domain == navigator_get_domain()) {
		fprintf(stderr, "Navigator event code %d received in filter\n", code);
	}
	else {
		fprintf(stderr, "Event domain %d code %d received in filter\n", domain, code);
	}
	return false;
}

static bool eventFilter(void* message)
{
    bps_event_t* event = (bps_event_t*)message;
    bool ret;
    ret = EventReceived(event);
    if (ret)
        return true;
    else if (previousEventFilter != NULL)
        return previousEventFilter(message);
    else
        return false;
}

Q_DECL_EXPORT int main(int argc, char **argv)
{
    Application app(argc, argv);

    HelloForeignWindowApp mainApp;

    previousEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter);

    return Application::exec();
}

 



 

 

Retired
psapra
Posts: 74
Registered: ‎07-22-2008
My Device: BlackBerry Z10

Re: Not getting screen events from Qt event filter

Please take a look at the below github sample which shows how to handle touch events correctly in a Cascades foriegn window.

 

https://github.com/blackberry/Cascades-Community-Samples/tree/master/GoodCitizenCascades

 

Thanks,
Pratik Sapra
Gaming & Apps Consultant
Developer Relations
@pratiksapra
New Contributor
JonathanLennox
Posts: 5
Registered: ‎03-28-2013
My Device: BlackBerry 10 Dev Alpha

Re: Not getting screen events from Qt event filter

Thanks -- that's very helpful.

 

Based on this code, what I'm concluding is that it's safe for the OpenGL thread to run a BPS event loop on its own screen_context_t, at the same time as QT is separately running its own event loop on a separate screen context?  That's very much not clear from the documentation.

 

Is it also safe for a private thread to subscribe to other BPS event types, in particular to subscribe to the same types as Qt is subscribing to?