[Development] [Interest] Modifying QQmlFileSelector selector at runtime without Loader or Component

Jérôme Godbout jerome at bodycad.com
Tue Dec 16 15:36:57 CET 2014


You may try to create the object dynamically based on the selector for the
source and/or the properties.
You could try Qt.createQmlObject() or Qt.createComponent()
along createObject(). Your onSelectorChanged could delete previous instance
if any and create a new one.
https://qt-project.org/doc/qt-5-snapshot/qtqml-javascript-dynamicobjectcreation.html

You could also use a empty string property and use it's changed event to
force a revaluate of a function call (this trick is used for i18n for
example):

Loader
{
  id: myLoader
  source: Qt.resolveUrl("MyItem.qml" + emptyString)
  property string emptyString: ""
}

Connections
{
  target: myCppObject
  onSelectorChanged: myLoader.emptyStringChanged()
}

Not sure if those can help you out, not sure what your selector does
actually.

On Tue, Dec 16, 2014 at 12:41 AM, Alan Alpert <416365416c at gmail.com> wrote:
>
> On Fri, Dec 12, 2014 at 8:29 PM, <achartier at fastmail.fm> wrote:
> >
> > Hello,
> >
> > I would like to modify the extraSelectors of QQmlFileSelector at runtime
> > and have QML load the new QML file from the appropriate selector folder.
> > I have gotten this to work by calling setExtraSelectors() from a C++
> > object I have exposed to QML and then forcing a re-evaluation of the
> > Loader's source property:
> >
> > Loader {
> >      id: myLoader
> >      source: Qt.resolvedUrl("MyItem.qml")
> > }
> >
> > Connections {
> >      target: myCppObject
> >      onSelectorChanged: myLoader.source = Qt.resolvedUrl("MyItem.qml")
> > }
> >
> > Now, for my use case I really need the ability to achieve the same
> > behavior without using Loader or Component. I essentially want something
> > like this:
> >
> > MyItem { }
> >
> > Connections {
> >      target: myCppObject
> >      onSelectorChanged: // when selector changes, the MyItem instance
> >      above is automatically resolved to the MyItem definition in the
> >      appropriate selector folder.
> >
> > How can this be accomplished?
>
> This cannot be accomplished (I actually tried last year). The problem
> is that you have an actual instance of MyItem there, and there's no
> way to magically map it into another instance. You have to destroy
> that instance and bring up a new one - which basically means Loader.
>
> What you probably want is to have certain parts of the instance shift,
> but not destroy the whole instance. For that I recommend using QtQuick
> States. You can have a base state, and then a list of property changes
> to things within the instance in a sub state and use transitions to
> animate it. That shifts the parts of the instance that need to,
> without destroying the whole thing. Or save state in another object
> (such as in a QtObject{} on the Loader) and bind your internal state
> to that so that you can use the Loader approach to recreate whole
> instances.
>
> PS: Moving to qt-interest since you didn't seem to be offering to
> develop this feature as a part of Qt.
>
> --
> Alan Alpert
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20141216/c1b16eef/attachment.html>


More information about the Development mailing list