2

I'd like to display/get a read on IMSI (tested it on Dev Alpha B). The issue is that I could get a read on others property of SimCardInfo such as Mobile Network Code, Mobile Country Code, Serial Number but IMSI (subscriberIdentifier). Here is the code

main.cpp

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/device/HardwareInfo>
#include <bb/device/SimCardInfo>

#include <QLocale>
#include <QTranslator>
#include <Qt/qdeclarativedebug.h>

using namespace bb::cascades;
using namespace bb::device;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    qmlRegisterUncreatableType<bb::device::HardwareInfo>("bb.device", 1, 0, "HardwareInfo", "");
    qmlRegisterUncreatableType<bb::device::SimCardInfo>("bb.device", 1, 0, "SimCardInfo", "");

    // this is where the server is started etc
    Application app(argc, argv);

    // localization support
    QTranslator translator;
    QString locale_string = QLocale().name();
    QString filename = QString( "hwinfo_%1" ).arg( locale_string );
    if (translator.load(filename, "app/native/qm")) {
        app.installTranslator( &translator );
    }

    //create object
    HardwareInfo hwInfo;
    SimCardInfo simcardInfo;

    QmlDocument *qml = QmlDocument::create("asset:///main.qml");

    qml->setContextProperty("_hardware", &hwInfo);
    qml->setContextProperty("_simcardinfo", &simcardInfo);


    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    Application::instance()->setScene(root);


    // we complete the transaction started in the app constructor and start the client event loop here
    return Application::exec();
    // when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
}

main.qml file

import bb.cascades 1.0
import bb.device 1.0

Page 
{
    Container 
    {   
        leftPadding: 20
        topPadding: 20
        Container 
        { 
            topMargin: 10
            layout: StackLayout 
                    {
                        orientation: LayoutOrientation.LeftToRight
                    }  
            Button
            {
                text: "retrieve"
                onClicked: 
                {
                    lbl0.text = "Model name: " + _hardware.modelName
                    lbl1.text = "IMEI: " + _hardware.imei
                    lbl2.text = "IMSI: " + _simcardinfo.subscriberIdentifier
                    lbl3.text = "SN: " + _simcardinfo.serialNumber
                    lbl4.text = "Mobile Network Code: " + _simcardinfo.mobileNetworkCode
                    lbl5.text = "Mobile Country Code: " + _simcardinfo.mobileCountryCode
                } 
            }
        }

        Container 
        {   
            layout: StackLayout {                        
                    }
            Label
            {
                id:lbl0
            }                    
            Label 
            {   
                id:lbl1      
            }
            Label
            {
                id:lbl2
            }        
            Label
            {
                id:lbl3
            }        
            Label
            {
                id:lbl4
            }        
            Label
            {
                id:lbl5
            }       
        }

    }
}

Any help is much appreciated.

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

KuroBerry
  • 21
  • 1

1 Answers1

1

You're declaring hwInfo and simCardInfo as stack variables, that means that after the constructor ends both variables no longer exist, so when the QML runtime tries to access the properties you assigned to them it just can't.

To make it work you need to declare those variables as heap variables so they can outlive their scope.

HardwareInfo* hwInfo = new HardwareInfo();
SimCardInfo* simcardInfo = new SimCardInfo();
qml->setContextProperty("_hardware", hwInfo);
qml->setContextProperty("_simcardinfo", simcardInfo);
Alex Díaz
  • 2,303
  • 15
  • 24