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
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE
Accepted Solution

How to get HardwareInfo in QML?

Hi Friends

I need to display data from BlackBerry as the IMEI and Pin in my application, I read in class:

bb :: HardwareID :: Pin ();

But there appears to be using For Example in Labels.

Thanks and Regards

Contributor
kuroberry
Posts: 30
Registered: ‎02-05-2013
My Device: Dev Alpha B

Re: How to get HardwareInfo in QML?

works for me
        
        #include <bb/device/HardwareInfo>
        
        using namespace bb::device;
        
        Q_DECL_EXPORT int main(int argc, char **argv)
        {
        
        ...
        
            //register
            
            qmlRegisterUncreatableType<bb::device::HardwareInfo>("bb.device", 1, 0, "HardwareInfo", "");
            
            //create object
            
            HardwareInfo hwInfo;
            
            qml->setContextProperty("_hardware", &hwInfo);
        
        ...
        
        }
        
        
        example to retrieve the data in qml file


        
        //display data on click
        Button
        {
            onClicked:
            {
                lbl0.text = "PIN: " + _hardware.pin
                lbl1.text = "IMEI: " + _hardware.imei                   
            }
        }
        
        Label
        {
            id:lbl0
        }                    
        Label
        {   
            id:lbl1
        }


reference
http://developer.blackberry.com/cascades/reference/bb__device__hardwareinfo.html

Developer
santito95
Posts: 134
Registered: ‎02-24-2013
My Device: BlackBerry Z10 LE

Re: How to get HardwareInfo in QML?

Thank you very much ..  

You code was worked, even now I have a problem with HardwareInfo :: ProcessorCount (), and does not appear

 

Contributor
kuroberry
Posts: 30
Registered: ‎02-05-2013
My Device: Dev Alpha B

Re: How to get HardwareInfo in QML?

not sure how to access it from public function as it cannot be accessed from property. maybe some one can chime in as I'd like to know also:smileyhappy:

Developer
dishooom
Posts: 103
Registered: ‎12-31-2012
My Device: Blackberry 9810

Re: How to get HardwareInfo in QML?

Why not create the processorCount alone as a seperate propertyMap and pass it on the QML.

int i = hwInfo->processorCount();
      
QDeclarativePropertyMap* propertyMap = new QDeclarativePropertyMap;
propertyMap->insert("processorCount", QVariant(QString::number(i)));
qml->setContextProperty("hwInfo", propertyMap);

 ... and access the value from QML as :

     text: hwInfo.processorCount

 

I hope this helps... :smileyhappy:

 

Needless to say, kuroberry the way you have exposed the other properties was good...

New Developer
Bartman_eh
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified

Re: How to get HardwareInfo in QML?

[ Edited ]

The tagged solution generates an error:
'qml' was not declared in this scope

Is it missing an include and/or namespace statement?  I tried adding "#include <bb/cascades/QmlDocument>" but I still get the error.

 

<noob alert>

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get HardwareInfo in QML?

qml is the main qml object created. if you create a new bb application using the wizard this code should be in the project.
----------------------------------------------------------
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
New Developer
Bartman_eh
Posts: 27
Registered: ‎01-04-2010
My Device: Not Specified

Re: How to get HardwareInfo in QML?

main.cpp calls applicationui.cpp so I put everything into applicationui.cpp and got it to work.

 

Thanks for help for a noob.

BlackBerry Development Advisor
tolang
Posts: 47
Registered: ‎04-19-2013
My Device: I love them all!

Re: How to get HardwareInfo in QML?

For what it's worth, HardwareInfo is registered for use in QML. import bb.device 1.0 Page { attachedObjects: [ HardwareInfo { id: hardware } ] Container { Label { text: hardware.deviceName } } }
Developer
andrewsmiley
Posts: 26
Registered: ‎07-22-2014
My Device: Z30, Z10, Q10, Passport

Re: How to get HardwareInfo in QML?

Cool, I have this sort of working.  If i use it to set the text of a button it works great.  But, if I try to use it to build a string it doesn't. 

 

So this is good:

Button {

                    id: pinTest

                text: _hardware.pin

                    onClicked: {

 

                    }

                }

 

But this is bad:

WebView {

                                        id: notificationSelectWebview

                                        url: 'http://whatever' _hardware.pin

                                    }