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
Posts: 16
Registered: ‎04-11-2013
My Device: z10
My Carrier: Verizon
Accepted Solution

Passing Data from C++ to QML on run time

Hi ,

does any one know how to pass data from CPP to QML on run time, I am not able to fin a suitable way

 

Initially I tried doing via setting up Property

 

below is eg code.

 

class MyClass: public QObject {
    Q_OBJECT

 

     Q_PROPERTY(bool navValue READ navValue WRITE setNavValue NOTIFY navValueChanged)

 

Q_SIGNALS:

     bool navValueChanged();

 

private:

        void setNavValue(const bool &navValue);
        bool navValue() const;

        bool m_navValue;

 

 

 

bool MyClass::setNavValue(const bool &navValue) {

    if (m_navValue == navValue)
            return;

    m_navValue = navValue;

    emit navValueChanged();
 }

 

bool MyClass::navValue() {
    return m_navValue;
  }

 

the "m_navValue "  is getting updated to "true" and "false" depending on Busniess Logic  and on what user selects.

 

 

Now I want this value to go to QML and update my back and foward button  if this value is true i will display otherwise not.

 

Can someone help in pointing me in right direction ?

 

 

Thanks

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

Re: Passing Data from C++ to QML on run time

[ Edited ]

Hi! In QML simply do something like this:

 

Button {
  visible: _myClass.navValue
}

where _myClass is the name of the class instance exported to QML. The field will be updated automatically when the signal is emitted.

 

Btw, it's better to pass primitive types by value, it's less effective to pass them by reference / pointer:

 

void setNavValue(bool navValue);

 

 


Andrey Fidrya, @zmeyc on twitter
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Passing Data from C++ to QML on run time

You shoud read this, there are a lot of ways: https://developer.blackberry.com/native/documentation/cascades/dev/integrating_cpp_qml/

 

Zmey's is a good one.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
New Developer
Posts: 16
Registered: ‎04-11-2013
My Device: z10
My Carrier: Verizon

Re: Passing Data from C++ to QML on run time

Thanks @Zmey for the help, The solution is working for me I tested it today

 

I  was not taking the correct refrence of the CPP class while exporting the variable "navValue"  in QML.