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
BeroboInc
Posts: 123
Registered: ‎07-08-2011
My Device: Torch 9800, Bold 9700
Accepted Solution

Compass Sample

Anyone actually been able to use this code in your own app? For some reason I am not getting it to do anything.

 

I dumped out a log in the CompassSensor filter method and it nevers seems to reach here. The Compass sample works fine but when I grab the CompassSensor.cpp and CompassSensor.hpp into my own app, no go.

 

I am doing the same thing

 


#include "CompassSensor.hpp"

   // Create the compass sensor object
   CompassSensor sensor;

    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);


    // Make the CompassSensor object available to the UI as context property
    qml->setContextProperty("_compass", &sensor);

 

and in my qml

 

 

 ImageView {
                    //scalingMethod: ScalingMethod.None
                    imageSource: "asset:///images/compass.png"
                    verticalAlignment: VerticalAlignment.Center
                    horizontalAlignment: HorizontalAlignment.Center
                    rotationZ: - _compass.azimuth

                    // Disable implicit animations to avoid ugly "jumps" when switching from 0 degrees to 360 degrees and vice versa
                    attachedObjects: ImplicitAnimationController {
                        propertyName: "rotationZ"
                        enabled: false
                    }
                }

 

 

and my project.pro file I added

 

CONFIG += qt warn_on debug_and_release cascades mobility
MOBILITY += sensors

 

 

Is there something I am missing?

 

 

 

Berobo Inc.
Police Scanner Radio / Alarm Clock lets you listen to Police scanners in your area!
http://www.berobo.com
_________________________________________________
Please click the Like button to thank the user that has helped you and
please mark post as solved when you have found the solution to your problem.
Developer
Bluenoser
Posts: 313
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Compass Sample

[ Edited ]

I was doing some testing with this yesterday. The following needs to be changed to get it to work.

 

   CompassSensor sensor;

 

change to

 

   CompassSensor *sensor = new Compass();

 

and


    qml->setContextProperty("_compass", &sensor);

 

change to


    qml->setContextProperty("_compass", sensor);

 

That should get it to work.

 

 

Developer
BeroboInc
Posts: 123
Registered: ‎07-08-2011
My Device: Torch 9800, Bold 9700

Re: Compass Sample

Sweet thanks a ton.

 

Works perfect.

 

Typo though.

 

     CompassSensor *sensor = new CompassSensor();

Coming from a java world I don't really understand why the previous version works in rims compass sample and not in my example as its the same code.

 

This line

CompassSensor sensor;

 

did actualy create the object code was reaching its constructer.

CompassSensor::CompassSensor(QObject *parent)

and constructor completed execution without any errors.

 

C++ is not my cup of tea.

 

 

Berobo Inc.
Police Scanner Radio / Alarm Clock lets you listen to Police scanners in your area!
http://www.berobo.com
_________________________________________________
Please click the Like button to thank the user that has helped you and
please mark post as solved when you have found the solution to your problem.
Developer
Bluenoser
Posts: 313
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Compass Sample

Typo was due to my own copying from my example and trying to change to meet your example. Don't forget to mark this problem as solved.