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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 1,638
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido
Accepted Solution

lockStateChanged() signal is not emitted

Can someone confirm if lockStateChanged() is working?

 

I can not get it work in c++ and QML as documented by BB.

 

I'm testing on the Z10 with gold sdk.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: lockStateChanged() signal is not emitted

[ Edited ]

I can confirm it works (just not reliably or in a timely fashion).

 

I also ignore the passed in state as I have found this unreliable as well and instead query within the slot using lockState().

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,638
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: lockStateChanged() signal is not emitted


BBSJdev wrote:

I can confirm it works (just not reliably or in a timely fashion).

 

I also ignore the passed in state as I have found this unreliable as well and instead query within the slot using lockState().

 


thanks but i don't have to have to check it all the time. I just want to use the signal.

 

well the slot is not even firing.

 

this is the code i'm using the BB docs

 

        // HomeScreen isn't a visible object so it must be wrapped as an
        // attached object.
        attachedObjects: [
            HomeScreen {
                id: myHomeScreen
                 
                onLockStateChanged: {
                    // Remember to use the property and not the parameter here.
                    console.log("Update " + lockState);
                    if (lockState == DeviceLockState.Unknown) {
                        console.log("No idea");
                    } else if (lockState == DeviceLockState.Unlocked) {
                        console.log("Unlocked");
                    } else if (lockState == DeviceLockState.ScreenLocked) {
                        console.log("Screen locked");
                    } else if (lockState == DeviceLockState.PasswordLocked) {
                        console.log("Password locked");
                    } else if (lockState == DeviceLockState.PinBlocked) {
                        console.log("PIN blocked");
                    }
                }
            }
        ]

 

 

 

Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: lockStateChanged() signal is not emitted

I don't use QML, I set up a SIGNAL/SLOT connection at the application level in C++.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,638
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: lockStateChanged() signal is not emitted

so is this the way? if so then the code below doesn't work for me.

 

#include <bb/Application>
#include <bb/platform/HomeScreen>
#include <bb/platform/WallpaperResult>
 
#include <QObject>
#include <QUrl>
 
class TestObject : public QObject
{
    Q_OBJECT
 
public Q_SLOTS:
    void onLockStateChanged(bb::platform::DeviceLockState::Type newState);
};
 
void onLockStateChanged(bb::platform::DeviceLockState::Type newState)
{
    if (newState == bb::platform::DeviceLockState::Unknown) {
        unknownLockState();
    } else if (newState == bb::platform::DeviceLockState::Unlocked) {
        deviceUnlocked();
    } else if (newState == bb::platform::DeviceLockState::ScreenLocked) {
        deviceScreenLocked();
    } else if (newState == bb::platform::DeviceLockState::PasswordLocked) {
        devicePasswordLocked();
    } else if (newState == bb::platform::DeviceLockState::PinBlocked) {
        devicePinBlocked();
    }
}
 
int main(int argc, char **argv)
{
    bb::Application app(argc, argv);
    bb::platform::HomeScreen homeScreen;
    TestObject testObject;
 
    QObject::connect(&homeScreen, SIGNAL( lockStateChanged(bb::platform::DeviceLockState::Type) ),
                     &testObject, SLOT( onLockStateChanged(bb::platform::DeviceLockState::Type) ));
 
    return app.exec();
}

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: lockStateChanged() signal is not emitted

[ Edited ]
	mHomeScreen = new HomeScreen(this);

	// Lock when phone/device locks
	bool b = connect(mHomeScreen,
			SIGNAL( lockStateChanged(bb::platform::DeviceLockState::Type) ),
			this, SLOT( onLockStateChanged(bb::platform::DeviceLockState::Type) ));
	Q_ASSERT(b);
	Q_UNUSED(b);

 

void StokLocker::onLockStateChanged(bb::platform::DeviceLockState::Type newState)
{
	Q_UNUSED(newState);

	bb::platform::DeviceLockState::Type state = mHomeScreen->lockState();

    if (state == bb::platform::DeviceLockState::ScreenLocked ||
    	state == bb::platform::DeviceLockState::PasswordLocked) {
        setLock(true);
    }
}

 Make sure to give it some time, sometimes it can take several seconds for the signal to come through.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.