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
New Developer
jadouber
Posts: 60
Registered: ‎12-20-2010
My Device: Black Berry Bold 9900
Accepted Solution

No objects being returned to QML calls?

Hi everyone,

 

I'm trying to create an instance of a C++ object on a QML form. For now I did this:

 

Game *game = new Game();

qml->setContextProperty("game", game);

 

This gives me the possibility to call functions from the game class in the QML file. (for example: game.getPlayer(0); The functions is being called (so that works).

 

My problem now is: getting an object from that class. For example:

 

Player* Game::getPlayer(intplayer)

{

Player* p = _players.at(player);

 

return p;

}

 

When I call this function, it will succeed (but when I try to log the result I get nothing. For example, the function Player::getName() returns nothing).

 

What am I doing wrong? I think the references to the obkect, but I don't know where.

 

Hopefully someone can help me with this!

 

Thanks in advance!

BlackBerry World submissions

YahtC - http://appworld.blackberry.com/webstore/content/24150872 - Check it out!

Free Yahtzee game for you and your friends! Step up to the challenge and see who is the Yahtzee-champion!

Leave a review, thanks!


Please use plain text.
Developer
simon_hain
Posts: 16,213
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: No objects being returned to QML calls?

Did you register the player class using qmlRegisterType? If not, do so (before calling setScene). Import the custom type in qml, then.
The class also has to extend QObject.
----------------------------------------------------------
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
Please use plain text.
New Developer
jadouber
Posts: 60
Registered: ‎12-20-2010
My Device: Black Berry Bold 9900

Re: No objects being returned to QML calls?

Simon_hain, thanks for the reponse!

 

Figured that out too.

 

I didn't register it, thus not making it available for contacting the class types. Silly me :Whistling:

 

It's all working perfectly now, thanks!

BlackBerry World submissions

YahtC - http://appworld.blackberry.com/webstore/content/24150872 - Check it out!

Free Yahtzee game for you and your friends! Step up to the challenge and see who is the Yahtzee-champion!

Leave a review, thanks!


Please use plain text.