PS: For reference, I'm talking about what would be the QML/Quick equivalent of the Plug and Paint example:

https://doc-snapshots.qt.io/qt6-dev/qtwidgets-tools-plugandpaint-app-example.html

Where the plugins bring UI components with themselves.

Às 18:24 de 14/09/2021, Rui Oliveira escreveu:
Hey,

I think we're speaking about different things. I've explored a bit and it seems that it's typical to create QML modules/plugins to expose new QML types that are found at runtime. But you still explicitly use those types. Like, an external project will add the "MyAwesomeAlgorithm" type and you can use that in your application's QML:

```
import <plugin.uri>

MyAwesomeAlgorithm
{
   id: "myAwesomeAlgo
}

```

But my goal is to not know about the types beforehand at all. It's basically the "copy the dll to the application folder and it'll magically show up as an option" pattern. The goal is to provide an extensibility framework, like eclipse, or web browser addons. Not just using a type defined elsewhere.

This is more or less what I mean: https://stackoverflow.com/questions/66618613/qml-c-classes-with-bring-your-own-component

Thanks,
Rui

Às 10:02 de 14/09/2021, Ulf Hermann escreveu:
Maybe I missed something, but this seems more like a solution to manage QML resources and modules that you know about at compile time.

The QML import path allows you to combine modules compiled separately in the context of different projects.

I'm talking about a runtime problem. Lemme try to explain with some simplified code. Allow me to leave a link to some markdown and syntax highlighted stuff:

https://gist.github.com/ruilvo/43365e67f6d3ea472531738fd5a52793

Do not start with something as low level as a plugin. Think of your code as logical units, defining different parts of your UI. Then create a QML module for each. The plugins are automatically generated. You don't have to care about them. Using "import Some.Module" in QML will load them as necessary.

You only need to make sure the QML engine knows about the relevant import paths. If you use the default directory layout as shown in the blog post, the default import path will be enough.

Otherwise you have to call QQmlEngine::addImportPath(). This is likely what you have to do if you want to combine modules from different projects.

You say that "import mytype" is not possible. However, there must be some starting point in your application. You need to have code that specifies a first plugin to load by file name. This can instead be phrased as a module URI. If you insist on not having an entry point main.qml, you can dynamically generate a two-line QML document and load it via QQmlComponent::setData():

// given moduleName and elementName:
QQmlEngine engine;
engine.addImportPath( ... );
QQmlComponent component(&engine);
const QString qml = QStringLiteral("import %1\n%2{}").arg(moduleName, elementName)
component.setData(qml.toUtf8(), QUrl());
QObject *myQmlObject = component.create();

best regards,
Ulf
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to