Using local types in remote qml files
-
I am currently trying to import qml files from a remote directory (see "Thread":http://qt-project.org/forums/viewreply/172115).
So far, I can load qml files that are in the remote dir, but when I try to use qmls (types) from my local directory, the access doesnt work "Type LocalType unavailable". How can I fix this? The access works if I use "Qt.createQmlObject", so I hope it will work for those imports too.For better comprehension here is an example filetree:
local (/home/user/workspace/qml)
- main.qml (imports page1.qml with remote import)
- button.qml
remote (192.168.1.23/qml)
- page1.qml (uses button.qml)
-
The types which are used in the QML file which comes from a remote directory import MUST be exposed into a type namespace which is imported by that remote file. You cannot use just the Button type without importing anything in page1.qml, as the component base url of page1.qml is different to the component base url of main.qml.
In short, if you want to do this, button.qml should be put into a module which is imported by both main.qml and page1.qml.
Cheers,
Chris. -
Thanks for the answer. So I will use your suggestion with the seperate module.
But I guess I didnt completly understand the first part of your answer, could you give a quick code example, if my example doesnt fit to what you meant?
main.qml:
@import QtQuick 2.2
import “http://192.168.178.33/content” as Remote // => is this the type namespace you talked about?Rectangle {
Remote.Page1 {}
}@ -
Well, that will import the types defined in the remote directory listing qmldir file into the Remote namespace.
But what I meant was that the local types used within a file from the remote should be within an explicit type namespace.
EG, let us assume that locally you have:
main.qml
MyButton.qmland remotely you have:
qmldir
Page.qmland for the sake of argument, if Page.qml has a declaration of an instance of MyButton in it, then this will not work unless MyButton comes from an explicitly defined type namespace (ie, not the implicit cwd import).
So, to make this work, you'd need to install a new, module-specification qmldir file plus the MyButton.qml file to your local QML2 import directory, and import that module within the MyForm.qml file (which comes from the remote).
eg, if you install the qmldir + MyButton.qml into /usr/lib/qt5/qml/com/your/company/components/ then you could do:
@
// main.qml
import QtQuick 2.2
import com.your.company.components 1.0
import “http://192.168.178.33/content” as RemoteItem {
Remote.Page {
// ...
}MyButton { // ... }
}
@where the (remote) Page.qml has:
@
// main.qml
import QtQuick 2.2
import com.your.company.components 1.0Item {
MyButton {
// this should work because when it's compiled
// the MyButton type is available from the (local) module.
}
}
@Cheers,
Chris.