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
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone
Accepted Solution

Push cpp file from QML?

Hello Guys,

 

  Can we push a cpp file from QML ? Some thing like

 

ActionItem {
                title: "Show Next Page"
                onTriggered: {
                    var page = pageDefinition.createObject();
                    navgationPane.push(page);
                }
                attachedObjects: ComponentDefinition {
                    id: pageDefinition
                    source:"sample.qml"
                }
               
            }

 

Above code pushes QML file onto the UI.The same way's, i would like to push a cpp file on to UI.

 

Possible solutions please?

 

Thanks,

Sha.

Developer
Posts: 16,842
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Push cpp file from QML?

if a cpp class extends a cascades class, like ImageView, Button or CustomControl, you can use it similar.
----------------------------------------------------------
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
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Push cpp file from QML?

Hi,

Please take a look at "Using C++ classes in QML" and below sections in this document:

http://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html

 

If you export C++ class following the guide above, then it's possible to create it using ComponentDefinition as well:

 

attachedObjects: [
  ...,
  ComponentDefinition {
    id: myComponentDefinition
    content: MyComponentExportedFromCPP {}
  }
]

There are other options as well such as creating the instance in C++ and exporting it to QML, or creating the instance in C++ and adding it to object hierarchy from C++ code etc.

 


Andrey Fidrya, @zmeyc on twitter
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Push cpp file from QML?

Thanks for the quick response.

 

My cpp constructor is having parmaeters such as Application* .

Will i have to do some changes to the code snippet mentioned above?

 

 

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

Re: Push cpp file from QML?

[ Edited ]

There's no way to give parameters to constructors in QML as far as I know. One option is to assign default values to them, such as:
Constructor(Application *app = NULL, ...) so the item can be constructed in QML, and exporting these parameters as properties too. Then I believe the properties can be set this way:

content: MyComponentExportedFromCPP {
  property: value
}

 

You'll have to export objects which are used during initialization to QML as well. Injecting the component from C++ code might be easier. This way you can call a single function in C++ code and create & initialize the object there.

Btw, passing Application object between object instances isn't really needed. It's a singleton and can be accessed from anywhere:

Application *app = Application::instance();


Andrey Fidrya, @zmeyc on twitter
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Push cpp file from QML?

Thanks for the clarification.

 

And also, how can I push a cpp file using Navigation pane. I tried to access the object of the Navgation pane in cpp and if i call a push fu nction, it's only accepting Page as parameter.But, how to push a Qobject class to NAvigation pane?

 

Am i clear?

 

Regards,

Sha.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Push cpp file from QML?

[ Edited ]

Zmey is right you pass parameters though properties exposed in the C++ class.

 

For the navigation pane, the only valid object is a 'Page' so you will need to derive from that or place Page in your Componant definition.

 

var page = pageDefinition.createObject();
navigationPane.push(page);

...

attachedObjects: [
    Page {
        id: pageDefinition
        MyCPPComponant  {
            myproperty: "hello"
        }
     }
]

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Trusted Contributor
Posts: 134
Registered: ‎05-31-2010
My Device: 8300
My Carrier: vodqafone

Re: Push cpp file from QML?

I will exactly write down my problem.

 

I'm having 2 Screens with 2 QML's in place.

 

My first Screen is directly invoked my Main class. So no problem here.

I'm binding this Screen with a QML which has Navigation pane in it.

 

Comming to second screen, the QML page is having a custom component which will have a button. I would like to have a click and some other events on this button. As pe my knowledge, i can't initiate an onclick of custom componenet's button from QML.

 

For this purpose, I tried to write a cpp class, bind it with QML and tried to access the Custom componet's button and performing click functionality.

 

If I'm trying this way, i'm failing in using navigation pane.

 

else if i push 2nd QML from 1st QML, i'm failing to bind the cpp file to QML where click functionaity is defined.

 

Suggest me the possible solution.

 

Thanks for your patience.

Sha.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Push cpp file from QML?

[ Edited ]

Nothing you've written is impossible, including initiating an onClick from QML (use onTouch or the Tap gesture) , at this stage you're going to have to post your code for us to look at.

 

However with no 'likes' and just a stream of new questions so far for the help received I'm starting to lose interest in your problem.

 

Your original question has been answered I believe so please mark a solution either one from Zmey or from me and then post the new problem with code in a new thread. I would suggest Zmeys first post as the one to mark as the most complete solution to your original question.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.