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
Posts: 656
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers
Accepted Solution

Signal - Slot Question

I have a VirtualKeyboardService that is setup this way :

constchar *uri = "bb.cascades.bps";
qmlRegisterType<bb::cascades::bps::BPSMonitor>(uri, 1, 0, "BPSMonitor");
qmlRegisterType<bb::cascades::bps::VirtualKeyboardService>(uri, 1, 0, "VirtualKeyboardService");

QML : 
 attachedObjects: [
            BPSMonitor {
                id: bpsMonitor
 
                //Receive events when the keyboard becomes visible or hides
                virtualKeyboardService: VirtualKeyboardService {
                    id: virtualKeyboardService
                    // Swipe from the bottom-left bezel towards the center of the
                    // screen to force the keyboard to be visible
                }
            }
]

 I don't know how to setup to be able to communicate from this service to the main app class.   I htink I need a signal / slot but don't understand how to set it up.   Need to send a simple TRUE when a certain key is pressed.  

 


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Signal - Slot Question

[ Edited ]

VirtualKeyboardService has these signals:

Q_SIGNALS:
void keyboardVisible();
void keyboardHidden();
void keyboardInfo(int height);

 

So you can add handlers for them in QML and call C++ object's methods:

 

onKeyboardVisible: {
  myCPPObject.someFunction();
}

 

The object must be registered to be accessible in QML:

qml->setContextProperty("myCPPObject", this);

Functions should be Q_INVOKABLE-s.

 

But why are you creating BPSMonitor & keyboardService in QML? This requires double bridging.

It's easier to create them in C++ code. Declare them in header file, then instantiate with operator new. Connect to the signals:

QObject::connect(virtualKeyboardService_, SIGNAL(keyboardVisible()), this, SLOT(onKeyboardVisible());

 Then implement onKeyboardVisible() slot.

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 656
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Signal - Slot Question

I got this way out of one of the sample apps and when I tried to set it up through C++ I had trouble.  Let me try that again and see if I can get it working this time.  Thanks.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Developer
Posts: 656
Registered: ‎02-03-2010
My Device: Z10 LE
My Carrier: Rogers

Re: Signal - Slot Question

Got it working with C++ as you described and removed QML code.  Thanks.


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing