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
Highlighted
New Contributor
Posts: 6
Registered: ‎06-02-2012
My Device: Playbook 2.0
My Carrier: N/A

ImageTracker sample code error

From here: https://developer.blackberry.com/cascades/reference/bb__cascades__imagetracker.html I got the sample code of using ImageTracker below. However, 
 
1. The 'ResourceTracker' should be 'ResourceState' as I couldn't find the 'Loaded' type defined in the ResourceTracker API
 
2. Even I change to 'ResourceState', the onStateChanged method still did not get called. the onCreationCompleted working though. I thought there might be a bug.
 
3. Isn't there is a better way to get the width&height of image src easily? I couldn't find a direct API but only throught the imagertracker...
 
 
I am using the Gold Build (1673).
 
 
Johnny
 
 
 
ImageView {
    id: myImageView
    attachedObjects: [
        ImageTracker {
            id: tracker
            imageSource: "images/image.png"
       
            onStateChanged: {
                if (state == ResourceTracker.Loaded)
                {
                    myImageView.image = tracker.image
                }
            }
        }
    ]
}
Developer
Posts: 169
Registered: ‎03-25-2011
My Device: Playbook, Z10 L.E.
My Carrier: Vodafone NL

Re: ImageTracker sample code error

[ Edited ]

Hi there,

 

The ImageTracker C++ is wrong as of Gold SDK 10.2.

 

Here's the fix:

 

void MyApp::setup() {
    mImageView = new ImageView();
    mImageTracker = new ImageTracker(QUrl("assets/image.png"));
    mImageTracker->setParent(this);  // Never forget to set the QOBject parent or else is Memory Leak!
// QNX will mark this as a bug... bool result = connect(mImageTracker, SIGNAL(stateChanged(bb::cascades::ResourceState::Type)), this, SLOT(onStateChanged(bb::cascades::ResourceState::Type))); Q_ASSERT(result); Q_UNUSED(result); // ... } void MyApp::onStateChanged(ResourceState::Type state) { if(state == ResourceState::Loaded) { mImageView->setImage(mImageTracker->image()); } }

I hope it helps.

Cheers.

Cheers!
Developer
Posts: 47
Registered: ‎04-01-2014
My Device: Z10, Q10
My Carrier: vodafone

Re: ImageTracker sample code error

I am still having trouble here. I am getting:

 

Object::connect: No such slot ApplicationUI:Smiley SurprisednStateChanged(bb::cascades::ResourceState::Type)

 

when running this code:

 

    bool result = connect(mImageTracker,
        SIGNAL(stateChanged(bb::cascades::ResourceState::Type)),
        this,
        SLOT(onStateChanged(bb::cascades::ResourceState::Type)));

BR,

 

René

 

Developer
Posts: 47
Registered: ‎04-01-2014
My Device: Z10, Q10
My Carrier: vodafone

Re: ImageTracker sample code error

When I change my code to:

 

    bool result = connect(mImageTracker,
        SIGNAL(stateChanged(bb::cascades::ResourceState::Type)),
        this,
        SLOT(onStateChanged(ResourceState::Type)));

 

I am getting:

 

QObject::connect: Incompatible sender/receiver arguments
        bb::cascades::ImageTracker::stateChanged(bb::cascades::ResourceState::Type) --> ApplicationUI:Smiley SurprisednStateChanged(ResourceState::Type)

at runtime.

 

BR,

 

René

Developer
Posts: 47
Registered: ‎04-01-2014
My Device: Z10, Q10
My Carrier: vodafone

Re: ImageTracker sample code error

Changing the code to:

 

    bool result = connect(mImageTracker,
        SIGNAL(stateChanged(ResourceState::Type)),
        this,
        SLOT(onStateChanged(ResourceState::Type)));

gives:

 

Object::connect: No such signal bb::cascades::ImageTracker::stateChanged(ResourceState::Type)

 

So really curious now how the correct code actually should look like ... thanks!

 

BR,

 

René

 

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: ImageTracker sample code error

QObject::connect cannot resolve namespaces. Slot declaration must have fully-qualified types as well and they must match exactly signal argument type names:

void onStateChanged(bb::cascades::ResourceState::Type state)
{ … }

If it's declared like this, original connect() line should work.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 47
Registered: ‎04-01-2014
My Device: Z10, Q10
My Carrier: vodafone

Re: ImageTracker sample code error

Hi,

 

OK - thanks! Go to know this "catch" ... when I use fully-quantied types, then the connect() succeeds. Still I have the problem that - though the image is loaded - my slot onStateChange() does not get called ...

 

BR,

 

René