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: 1,531
Registered: ‎07-14-2008
My Device: Z10
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,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

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. :smileyhappy:

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

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");
                    }
                }
            }
        ]

 

 

 

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

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. :smileyhappy:

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

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,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.