Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can a QQuickView have more than one Context Object?
Qt 6.11 is out! See what's new in the release blog

Can a QQuickView have more than one Context Object?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antonyprojr
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Did you register all your objects class property ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        Did you register all your objects class property ?

        A Offline
        A Offline
        antonyprojr
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved