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. Accessing QML components in main.qml
Forum Updated to NodeBB v4.3 + New Features

Accessing QML components in main.qml

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.6k 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.
  • M Offline
    M Offline
    malikaliabbas
    wrote on last edited by
    #1

    Hello,

    I am willing to access some QML Components in main.qml. detail about the matter is that On receiving Signal from Qt I have to enable the mouse area of some components which are not created in main.qml but these components are part of the application. Can anybody give me any idea how to make Mouse Area enable.

    any help is appreciated

    Regards,
    Ali Abbas

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can connect the signal in the file that HAS the MouseArea, and then just set the "active" property of that MouseArea. That will work if signal is sent by contextObject (so, one created in C++ for example).

      In other circumstances, you can try propagating the signal yourself through your object hierarchy. But, to be honest, I am not 100% sure I understand your problem.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        malikaliabbas
        wrote on last edited by
        #3

        I am in a process to develop a game using Qt (C++) and QML. Game logic is developed using C++ and GUI's stuff is built using QML. In game, I have to enable and disable Mouse Area of two 'QDeclarativeItems'. 'onClicked' event I disable MouseArea of respective 'QDeclarativeItem'. After applying game conditions, I have to enable MouseArea of that DeclarativeItem. What I am doing is that I send a signal from C++ to QML to enable MouseArea. In 'main.qml' I receive signal but respective Item is not in 'main.qml'. How can I access particular Item to enable its MouseArea. I Hope now you can understand my problem

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          What I was trying to say is that you can connect to the signal not only in main.qml, but also in other files - signals from C++ are globally available (at least in apps I've written, maybe unknowingly I was using some special feature - but I doubt it). This way, you can handle the signal as you please: in main.qml only, in your other file, or in both at the same time.

          If you don't like it, you can try and get to your declarative item through "children" property (QML has hierarchy of children).

          Another alternative is to get through the hierarchy using custom signals and slots. main.qml would send a singnal to it's children, the kids will propagate that to their children, and so on until your DeclarativeItem gets it.

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            malikaliabbas
            wrote on last edited by
            #5

            Thanks for your suggestion. I have tried the first option but I was not able to get required results.

            now I'll try the second one i.e. through accessing children

            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