[Qt-qml] Loading external QML files

Ben Marinic ben at combinationstudios.com
Wed Jul 28 11:48:57 CEST 2010


Thanks Martin.  I have tried the following but get the compile error:  
QML Connections: Cannot assign to non-existent property  
"onTouchPointHit".  What have I done wrong?  Another problem I have is  
that I don't necessarily know how many child QML files I will have  
(the QML is generated by a Flex application) and therefore can't setup  
all of my connections before hand in my Player.qml file.  Is there a  
way to have a generic connection/signal which all children dispatch  
and the Player.qml handles?  I would also need to include a value in  
my signal (a string reference to another QML file) which only the  
child knows.  I'm not sure if you can do this with signals?

//Player.qml
import Qt 4.7
  Item {
      width: 200
      height: 200
      Loader {
          id: screenLoader
          source: "Node1.qml"
      }
      Connections {
          target:screenLoader.item; onTouchPointHit:console.log("touch  
point hit")
      }
  }

//Node1.qml
import Qt 4.7
Item {
     id: node1
     width: 300
     height: 300
     signal onTouchPointHit
     MouseArea {
         onClicked: node1.onTouchPointHit()
     }
}
Thanks
Ben

On 28 Jul 2010, at 03:02, Martin Jones wrote:

> Another option is to have the loaded QML expose some signals that  
> you can
> connect to.  For example if you load:
>
> // MyItem.qml
> Item {
>    id: myItem
>    signal closeView
>
>    MouseArea {
>        onClicked: myItem.closeView()
>    }
> }
>
> using:
>
> Loader {
>    id: myLoader
>    source: "MyItem.qml"
> }
>
> then you can create a connection to handle the signal:
>
> Connections { target: myLoader.item; onCloseView: myLoader.source =  
> "" }
>
> Martin.
>
> On Wed, 28 Jul 2010 11:18:11 am Kennedy Aaron (Nokia-MS-Qt/Brisbane)  
> wrote:
>> Hi,
>>
>> QML does not currently expose any “event” like concept.  It might  
>> in the
>> future.
>>
>> For now, you can call methods in the parent QML file directly if  
>> you want,
>> although that does restrict the contexts within which the sub-file  
>> can
>> reasonably be used.
>>
>> Cheers,
>>
>> Aaron
>>
>>
>> On 28/07/10 2:13 AM, "ext Ben Marinic" <ben at combinationstudios.com>  
>> wrote:
>>
>> Thank you Gregory.  My newbie questions continue.  Where in the  
>> docs should
>> I look regarding custom events?  Can I add a listener to the loader
>> instance which is listening for a custom event triggered by the  
>> child QML
>> file?  In my example a mouse event from the child QML file needs to  
>> bubble
>> up to the parent QML file which will handle the event.  In the  
>> event I
>> would like to have a few custom properties.
>>
>> Thanks
>> Ben
>>
>>
>> On 27 Jul 2010, at 11:59, Gregory Schlomoff wrote:
>>
>> You're looking for the Loader element :)
>> Have a look at the doc:
>> http://doc.trolltech.com/main-snapshot/qdeclarativeelements.html
>>
>>
>> On Tue, Jul 27, 2010 at 5:53 PM, Ben Marinic <ben at combinationstudios.com 
>> >
>> wrote: Hi
>>
>> I'm new to QML - having used Flex for many years. Is there a way  
>> for a QML
>> file to load another QML file on demand? Something like the way an  
>> image
>> can be loaded - passing in the image location into the source  
>> property. I
>> looked at the File class but can't quite figure out how to  
>> implement it
>> for my situation. I have button and need to load a particular QML  
>> file.  I
>> guess this would be the equivalent of a Flash SWF loading another  
>> SWF (if
>> you are familiar with Flash).
>>
>> Thanks for your help.
>> Ben
>> Ben Marinic
>> Combination Studios Ltd
>> e. ben at combinationstudios.com
>> t. +44 (0)20 7193 2000
>> m. +44 (0)7813 147 159
>>
>>
>>
>>
>>
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-qml
>>
>>
>>
>>
>> Ben Marinic
>> Combination Studios Ltd
>> e. ben at combinationstudios.com
>> t. +44 (0)20 7193 2000
>> m. +44 (0)7813 147 159
>
> -- 
> Martin

Ben Marinic
Combination Studios Ltd
e. ben at combinationstudios.com
t. +44 (0)20 7193 2000
m. +44 (0)7813 147 159









More information about the Qt-qml mailing list