Accessing QML components in main.qml
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
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.
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
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.
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