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
vencedor
Posts: 18
Registered: ‎11-08-2012
My Device: Blackberry 10 Dev Alpha B
My Carrier: ??
Accepted Solution

QTimer and qmlRegisterType

I think it is time for me to consult the forum world about my issue. It seems so simple and yet I could not find the cause of the problem. I started having problems after installing SDK Gold version

 

I would like to use QTimer on Cascades.

In my <apps>.cpp, I registered the object as:

                                  qmlRegisterType<QTimer> ("my.library", 1, 0, "QTimer");

In main.qml, I imported it as:

                                  import my.library 1.0

and attached it on a Label as follows:

 

             attachedObjects: [
                QTimer{
                    id : timer
                    property int f : 0                               
                    interval : 1000
                    onTimeout:{
                        f += 1;
                        timerLabel.text = "Time: " + f;  // timerLabel is the id of Label which QTimer is attached
                    }  
                }
            ]

 

Thanks for any help!   

 

 

 

If you find my post helpful, please click like :smileyhappy:
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QTimer and qmlRegisterType

Seems about right. You don't actually describe what problem you're seeing...

Also, did you check the log output? Generally issues in the QML will be spelled out pretty clearly with an error message in the log output. Look for the docs on the "slog2info" way of getting the data, or how to use the new log feature in Momentics (in the release notes, I would assume, though I don't recall where that feature is covered).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
vencedor
Posts: 18
Registered: ‎11-08-2012
My Device: Blackberry 10 Dev Alpha B
My Carrier: ??

Re: QTimer and qmlRegisterType

The codes for attaching QTimer apparently do not work. The apps only show blackscreen with Blackberry 10 logo in the middle. When I disable/commented the codes, then the apps work fine, but of course without the timer.

 

Thanks

 

 

this is interesting after issuing slog2info command:

 

Dec 15 11:56:26.369 com.example.Mathon.testDev_mple_Mathondb5dac1
8.42434760              default   9000  bb::cascades::QmlDocument
: error when loading QML from:   QUrl( "file:///apps/com.example.
Mathon.testDev_mple_Mathondb5dac18/native/assets//main.qml" )  
Dec 15 11:56:26.370 com.example.Mathon.testDev_mple_Mathondb5dac1
8.42434760              default   9000    --- errors:  (file:///a
pps/com.example.Mathon.testDev_mple_Mathondb5dac18/native/assets/
/main.qml:5:1: module "my.library" is not installed
    import my.library 1.0    //attached class from C++
    ^)
Dec 15 11:56:26.370 com.example.Mathon.testDev_mple_Mathondb5dac1
8.42434760              default   9000  bb::cascades::QmlDocument
:createRootObject document is not loaded or has errors, can't cre
ate root

 

and this:

 

Dec 15 11:56:26.373 com.example.Mathon.testDev_mple_Mathond
b5dac18.42434760              default      0  PPSEventHandl
er::Failed to read PPS object

If you find my post helpful, please click like :smileyhappy:
Please use plain text.
Developer
dtater
Posts: 158
Registered: ‎01-11-2010
My Device: 9700 | 9900 | PlayBook | Dev Alpha
My Carrier: Many :)

Re: QTimer and qmlRegisterType

I actually had this problem yesterday, and my solution was to take a *very* close look at the build.prop file that is included with the Qtimer demo.  Check the link here:

 

https://developer.blackberry.com/cascades/documentation/dev/signals_slots/signals_slots_create_timer...

 

That example has a demo applicaiton.  import it and run it on your device.  If it runs, then you know the code they provided works and should not cause any problems :smileyhappy:

 

 

That's what i did aafter spending several hous pouring over my code / thinking why wont it work!?

 

Turns out that my build.prop was out of whack.

 

 

Best of luck!

- - - - - - - - - -
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QTimer and qmlRegisterType

vencedor, after looking at the log output, I would suggest that your code is not actually executing the line that does the registration.

 

When reading your first post, I compared what you have to what I used. It's basically the same. Should work. The fact it says the module is not installed makes me think it never did the registration.

 

Here's what I've got. Note I just include it in bb.cascades, mainly to express my feeling there should have been something like it in there in the first place! ;-)

 

qmlRegisterType<QTimer>("bb.cascades", 1, 0, "QTimer");

In my QML I just have the usual "import bb.cascades 1.0" but I see no reason to think what you're doing shouldn't have worked as well.

 

Put some debugging before/after the qmlRegisterType() call, and see when if it executes, and when it does relative to the error output.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
vencedor
Posts: 18
Registered: ‎11-08-2012
My Device: Blackberry 10 Dev Alpha B
My Carrier: ??

Re: QTimer and qmlRegisterType

After trying several scenarios and working on your suggestions, I finally found what causes the problem. In the original code, it could register the object and reached import statement, but it never executed the attachedObjects part.

 

What I did is I renamed my main.qml into a different one (timeTrial.qml), and created a new main.qml. Then I access timeTrial.qml through navigationPane. It worked without any code changes.

 

Can somebody provide an insight how this is so?

 

It goes like this:

cpp file (object registration)  ->  main.qml  -> timeTrial.qml (import my.library 1.0)

 

Thanks a lot!

If you find my post helpful, please click like :smileyhappy:
Please use plain text.