Can a QQuickView have more than one Context Object?



  • I'm developing a application that uses QML and C++, to expose the C++ functions to the QQuickView i use setContextObject, that way the QML code can access my own C++ functions, and it's working pretty well, however, i have another QObject that I want to expose to the QML code too. But I'm unable to make a second call to setContextObject or to setContextProperty be accepted by the QML code.

    How can I have two QObjects accessible by the same QML\QQuickView instance?


  • Lifetime Qt Champion

    Hi,

    Can you show the code you use for your setContextProperty calls ?

    Did you register all your objects class property ?



  • @SGaist Sorry, the error is caused by a poor class design. At the first moment I'm declaring the QQuickView in a parent class (the first class), and passing to the parent class a pointer of the child class (the second class), but the pointer was a QObject and not MyClass. So i believe that the problem happens when passes the pointer to the parent class and looses the information about MyClass. Redesigned my class structure and everything works.


  • Lifetime Qt Champion

    Great !

    Glad you found out and thank for sharing.

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know that a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.