@wysota
I have been playing with this for a while and made some test. So far it's a much better solution than what I had initially. I am very grateful that you took the time to explain everything and provided all the help!
Component defines a component inline, not refers to an external component. Which is actually pretty stupid that there is no element to load an external component like that
I was also thinking that you should be able to just have a path to an external component and load it that way. Then again there is
import "some.qml" as ComponentName
import "some.qml" as ComponentName
To copy to clipboard, switch view to plain text mode
which provides that functionality. The problem with this is that you have to provide an absolute path for components that are not in the qrc: resources. Since an import can not have a relative or dynamically build path there really should be an option to directly load/link a component based on an url. It would make some things easier.
@anda_skoa
That would essentially hard code it to one specific component. I need to dynamically load different qml files depending on the desired task. The path "../network/NetworkManagerQml.qml" was only there to point out it doesn't work. Technically it would be more like this:
Component {
id: networkManager
url: resolvePath(someTask);
}
function resolvePath(someTask) {
// get path to some qml file. Where the qml file
// can be different depending on the desired task
}
Component {
id: networkManager
url: resolvePath(someTask);
}
function resolvePath(someTask) {
// get path to some qml file. Where the qml file
// can be different depending on the desired task
}
To copy to clipboard, switch view to plain text mode
But that leads to the same problem. I neglected to go into more details because I thought that would be clear based on the ongoing discussion. I should have been more specific.
So far this
function loadRresource(requiredTask)
{
// get path to qml file depending on the task
var path = resolvePath(requiredTask);
var component = Qt.createComponent(path);
if (component.status == Component.Ready) {
var obj = component.createObject(myText);
if (null == obj)
console.log("Error creating component: " + component.errorString());
else
{
// this is the tricky part... The obj might need some sort of setup to work
// find a common way to initialize various components. e.g. setting up signals and slots
obj.someSetupFunctionHook();
}
}
else
console.log("Error loading component " + component.errorString());
}
function loadRresource(requiredTask)
{
// get path to qml file depending on the task
var path = resolvePath(requiredTask);
var component = Qt.createComponent(path);
if (component.status == Component.Ready) {
var obj = component.createObject(myText);
if (null == obj)
console.log("Error creating component: " + component.errorString());
else
{
// this is the tricky part... The obj might need some sort of setup to work
// find a common way to initialize various components. e.g. setting up signals and slots
obj.someSetupFunctionHook();
}
}
else
console.log("Error loading component " + component.errorString());
}
To copy to clipboard, switch view to plain text mode
seams to work best.
p.s. I will make sure I got it right before I mark the thread as solved. But so far I'm pretty happy with the result.
Bookmarks