[Qt-qml] Loading external QML files

Martin Jones martin.jones at nokia.com
Wed Jul 28 04:02:03 CEST 2010


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




More information about the Qt-qml mailing list