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: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
My Carrier: Blackberry

Get Device Pin using DeviceInfo

[ Edited ]

Hi,

  Iam trying to get the device pin programatically

 

What I have done

 

1)In the .pro file I have included    LIBS += -lbbdevice

2)In the header file of my class I have included    #include<bb/device/HardwareInfo>

3)I have enabled the permission to access the device info

 

My Problem is:

 

In my class I used the following code to get the pin

 

void Home::init()
{
    QString deviceId = pin();
    qDebug()<<"pin"<<deviceId;
}

 But the following error is shown 

error: 'pin' was not declared in this scope.

 

Where Iam wrong?Any one plz help me out Iam stucked here Smiley Sad

 

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Get Device Pin using DeviceInfo

you cannot use a method just like that, it belongs to an object that you have to create before.
like
HardwareInfo hardwareInfo;
QString deviceId = hardwareInfo.pin();
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Get Device Pin using DeviceInfo

Hi, 

 

I am not very familiar with C++, but I need to access the pin too. Can I assume that all I need to do is:

 

1) Add to my applicationui.cpp:

#include <bb/device/HardwareInfo>

 

2) And inside 

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
QObject(app)
{
... HardwareInfo hardwareinfo; QString devicePIN = hardwareinfo.pin(); }

 3) .pro

-lbbdevice

 

and I can just call from my QML devicePIN?

 

Do I need to do something else?

Developer
Posts: 243
Registered: ‎07-22-2011
My Device: BlackBerry Z10
My Carrier: AirTel

Re: Get Device Pin using DeviceInfo

Hi,
If you want to access the devicePIN variable from cpp you have set the property of that qml in cpp.

Regards,
Lakshman K
----------------------------------------------------------
Feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Get Device Pin using DeviceInfo

[ Edited ]

You don't need to expose QML property from Cpp to QML.

Just import bb.device and use HardwareInfo directly

QML

import bb.device 1.0 // or 1.2 (10.2 API)

Container{

    Label{
        text: info.pin
    }

    attachedObjects:[
        HardwareInfo{
            id: info
        }
    ]
}

C++

as 

using namespace bb::device;

// and then
HardwareInfo info;
qDebug() << "My pin: " << info.pin();

 or

bb::device::HardwareInfo info;
qDebug() << "My pin: " << info.pin();

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 74
Registered: ‎12-17-2009
My Device: Z30
My Carrier: O2

Re: Get Device Pin using DeviceInfo

Thanks! That made my life so much easier!