Discussion:
QQmlExtensionPlugin not loading
(too old to reply)
Jesper Huijgens
2018-03-09 13:04:45 UTC
Permalink
Raw Message
Hi all,

For our project we see that QQmlExtensionPlugins are not loaded.
I made a very basic example project that creates a QQmlExtensionPlugin
and an application that should use. The plugin, with the corresponding
qmldir, are placed in a plugin subdir in the output directory of the
application.
The application sets both libraryPath and pluginPath. I output the
pluginPathList(), I see what I think are the correct folders on the
debug output.

I placed a qDebug() in registerTypes of the plugin. I see nothing on the
debug output.

Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries being loaded.
But not my plugin.

I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.

Kind regards,
Jesper
Martin Leutelt
2018-03-09 13:20:18 UTC
Permalink
Raw Message
From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 2:04 PM
Subject: [Interest] QQmlExtensionPlugin not loading

Hi all,

For our project we see that QQmlExtensionPlugins are not loaded.
I made a very basic example project that creates a QQmlExtensionPlugin
and an application that should use. The plugin, with the corresponding
qmldir, are placed in a plugin subdir in the output directory of the
application.
The application sets both libraryPath and pluginPath. I output the
pluginPathList(), I see what I think are the correct folders on the
debug output.

I placed a qDebug() in registerTypes of the plugin. I see nothing on the
debug output.

Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries being loaded.
But not my plugin.




Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for debugging plugins for Qt itself, not the QML engine.

I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.

Kind regards,
Jesper





Regards
Martin


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Jesper Huijgens
2018-03-09 13:24:56 UTC
Permalink
Raw Message
With QML_IMPORT_TRACE I see again the right folders. But I do not see
any attempt of loading the plugin.

Kind regards,
Jesper

On 09-03-18 14:20, Martin Leutelt wrote:
>
> *From: * Jesper Huijgens <***@sioux.eu>
> *To: * <***@qt-project.org>
> *Sent: * 3/9/2018 2:04 PM
> *Subject: * [Interest] QQmlExtensionPlugin not loading
>
> Hi all,
>
> For our project we see that QQmlExtensionPlugins are not loaded.
> I made a very basic example project that creates a
> QQmlExtensionPlugin
> and an application that should use. The plugin, with the
> corresponding
> qmldir, are placed in a plugin subdir in the output directory of the
> application.
> The application sets both libraryPath and pluginPath. I output the
> pluginPathList(), I see what I think are the correct folders on the
> debug output.
>
> I placed a qDebug() in registerTypes of the plugin. I see nothing
> on the
> debug output.
>
> Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries being
> loaded.
> But not my plugin.
>
>
> Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for debugging
> plugins for Qt itself, not the QML engine.
>
> I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.
>
> Kind regards,
> Jesper
>
>
>
> Regards
> Martin
>
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Martin Leutelt
2018-03-09 13:44:34 UTC
Permalink
Raw Message
From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 2:24 PM
Subject: Re: [Interest] QQmlExtensionPlugin not loading


With QML_IMPORT_TRACE I see again the right folders. But I do not see any attempt of loading the plugin.


You're missing an import statement in your main.qml to load your plugin (see http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html).
addPluginPath()/addLibraryPath() isn't necessary for QML plugins, but (depending on your project hierarchy or how your application is installed/deployed) you might need addImportPath().




Kind regards,
Jesper


Regards
Martin





On 09-03-18 14:20, Martin Leutelt wrote:


From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 2:04 PM
Subject: [Interest] QQmlExtensionPlugin not loading

Hi all,

For our project we see that QQmlExtensionPlugins are not loaded.
I made a very basic example project that creates a QQmlExtensionPlugin
and an application that should use. The plugin, with the corresponding
qmldir, are placed in a plugin subdir in the output directory of the
application.
The application sets both libraryPath and pluginPath. I output the
pluginPathList(), I see what I think are the correct folders on the
debug output.

I placed a qDebug() in registerTypes of the plugin. I see nothing on the
debug output.

Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries being loaded.
But not my plugin.




Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for debugging plugins for Qt itself, not the QML engine.

I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.

Kind regards,
Jesper





Regards
Martin


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Jesper Huijgens
2018-03-09 13:53:36 UTC
Permalink
Raw Message
Ok, I see what the problem is.

I expected Qt to automatically register the types. Even without the
import statement.

--
Jesper

On 09-03-18 14:44, Martin Leutelt wrote:
>
> *From: * Jesper Huijgens <***@sioux.eu>
> *To: * <***@qt-project.org>
> *Sent: * 3/9/2018 2:24 PM
> *Subject: * Re: [Interest] QQmlExtensionPlugin not loading
>
> With QML_IMPORT_TRACE I see again the right folders. But I do not
> see any attempt of loading the plugin.
>
>
> You're missing an import statement in your main.qml to load your
> plugin (see http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html).
> addPluginPath()/addLibraryPath() isn't necessary for QML plugins, but
> (depending on your project hierarchy or how your application is
> installed/deployed) you might need addImportPath().
>
>
>
> Kind regards,
> Jesper
>
>
> Regards
> Martin
>
>
>
> On 09-03-18 14:20, Martin Leutelt wrote:
>>
>> *From: * Jesper Huijgens <***@sioux.eu>
>> <mailto:***@sioux.eu>
>> *To: * <***@qt-project.org> <mailto:***@qt-project.org>
>> *Sent: * 3/9/2018 2:04 PM
>> *Subject: * [Interest] QQmlExtensionPlugin not loading
>>
>> Hi all,
>>
>> For our project we see that QQmlExtensionPlugins are not loaded.
>> I made a very basic example project that creates a
>> QQmlExtensionPlugin
>> and an application that should use. The plugin, with the
>> corresponding
>> qmldir, are placed in a plugin subdir in the output directory
>> of the
>> application.
>> The application sets both libraryPath and pluginPath. I
>> output the
>> pluginPathList(), I see what I think are the correct folders
>> on the
>> debug output.
>>
>> I placed a qDebug() in registerTypes of the plugin. I see
>> nothing on the
>> debug output.
>>
>> Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries
>> being loaded.
>> But not my plugin.
>>
>>
>> Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for
>> debugging plugins for Qt itself, not the QML engine.
>>
>> I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.
>>
>> Kind regards,
>> Jesper
>>
>>
>>
>> Regards
>> Martin
>>
>>
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org <mailto:***@qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org <mailto:***@qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> ***@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
Jesper Huijgens
2018-03-09 14:43:29 UTC
Permalink
Raw Message
Hello,

First of all. Thanks for the help so far, got me quite a bit further.

What I try to achieve is having plugins that can inject e.g. a button on
a toolbar. Simply put: an application that can be extended via plugins.
During development I do not know what plugins there will be at runtime.
So I do not know what to import in Main.qml.
All plugins also implement an interface I made with a method /initPlugin/.
In this method the plugin can create a qml object and inject it into the
already running UI (Calling this method is triggered from within the
main UI).

Easiest/simplified example would be:

--------------------
*MyPlugin.cpp*:
    void MyPlugin::registerTypes (const char* uri) // uri => "MyPlugin"
    {
        qmlRegisterType<MyPluginType>(uri, 1, 0, "MyPluginType");
    }

    void MyPlugin::initPlugin (QObject* objectInsideTheRunningUI)
    {
        QQmlEngine* engine =
QQmlEngine::contextForObject(objectInsideTheRunningUI)->engine();
        auto newButton = createButtonUsingEngine(engine,
"MyPluginButton.qml"); // Method creating QQmlComponent, and calling
QQmlComponent.create() on it
    }

*MyPluginButton.qml*:
import QtQuick 2.10
import MyPlugin 1.0 // *Here I get module MyPlugin is not installed.*

Item {
    MyPluginType {}
}
--------------------

TL;DR:
    If I import my plugin module in Main.qml it works like a charm.
    If I dynamically create a qml object which call the same import
call (import MyPlugin 1.0) it does not work. I get module MyPlugin is
not installed.

In tried calling the registerTypes method inside initPlugin. This seems
to work. But I am curious why it works if I call import in Main.qml and
not in MyPluginButton.qml, and what I should do to make it work.

Thanks.

Kind regards,
Jesper

On 09-03-18 14:53, Jesper Huijgens wrote:
> Ok, I see what the problem is.
>
> I expected Qt to automatically register the types. Even without the
> import statement.
>
> --
> Jesper
>
> On 09-03-18 14:44, Martin Leutelt wrote:
>>
>> *From: * Jesper Huijgens <***@sioux.eu>
>> *To: * <***@qt-project.org>
>> *Sent: * 3/9/2018 2:24 PM
>> *Subject: * Re: [Interest] QQmlExtensionPlugin not loading
>>
>> With QML_IMPORT_TRACE I see again the right folders. But I do not
>> see any attempt of loading the plugin.
>>
>>
>> You're missing an import statement in your main.qml to load your
>> plugin (see http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html).
>> addPluginPath()/addLibraryPath() isn't necessary for QML plugins, but
>> (depending on your project hierarchy or how your application is
>> installed/deployed) you might need addImportPath().
>>
>>
>>
>> Kind regards,
>> Jesper
>>
>>
>> Regards
>> Martin
>>
>>
>>
>> On 09-03-18 14:20, Martin Leutelt wrote:
>>>
>>> *From: * Jesper Huijgens <***@sioux.eu>
>>> <mailto:***@sioux.eu>
>>> *To: * <***@qt-project.org> <mailto:***@qt-project.org>
>>> *Sent: * 3/9/2018 2:04 PM
>>> *Subject: * [Interest] QQmlExtensionPlugin not loading
>>>
>>> Hi all,
>>>
>>> For our project we see that QQmlExtensionPlugins are not
>>> loaded.
>>> I made a very basic example project that creates a
>>> QQmlExtensionPlugin
>>> and an application that should use. The plugin, with the
>>> corresponding
>>> qmldir, are placed in a plugin subdir in the output
>>> directory of the
>>> application.
>>> The application sets both libraryPath and pluginPath. I
>>> output the
>>> pluginPathList(), I see what I think are the correct folders
>>> on the
>>> debug output.
>>>
>>> I placed a qDebug() in registerTypes of the plugin. I see
>>> nothing on the
>>> debug output.
>>>
>>> Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries
>>> being loaded.
>>> But not my plugin.
>>>
>>>
>>> Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for
>>> debugging plugins for Qt itself, not the QML engine.
>>>
>>> I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.
>>>
>>> Kind regards,
>>> Jesper
>>>
>>>
>>>
>>> Regards
>>> Martin
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> ***@qt-project.org <mailto:***@qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> ***@qt-project.org <mailto:***@qt-project.org>
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> ***@qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
Martin Leutelt
2018-03-09 15:41:57 UTC
Permalink
Raw Message
From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 3:43 PM
Subject: Re: [Interest] QQmlExtensionPlugin not loading


Hello,

First of all. Thanks for the help so far, got me quite a bit further.

What I try to achieve is having plugins that can inject e.g. a button on a toolbar. Simply put: an application that can be extended via plugins.
During development I do not know what plugins there will be at runtime. So I do not know what to import in Main.qml.
All plugins also implement an interface I made with a method initPlugin.
In this method the plugin can create a qml object and inject it into the already running UI (Calling this method is triggered from within the main UI).

Easiest/simplified example would be:

--------------------
MyPlugin.cpp:
    void MyPlugin::registerTypes (const char* uri) // uri => "MyPlugin"
    {
        qmlRegisterType<MyPluginType>(uri, 1, 0, "MyPluginType");
    }

    void MyPlugin::initPlugin (QObject* objectInsideTheRunningUI)
    {
        QQmlEngine* engine = QQmlEngine::contextForObject(objectInsideTheRunningUI)->engine();
        auto newButton = createButtonUsingEngine(engine, "MyPluginButton.qml"); // Method creating QQmlComponent, and calling QQmlComponent.create() on it
    }

MyPluginButton.qml:
import QtQuick 2.10
import MyPlugin 1.0 // Here I get module MyPlugin is not installed.

Item {
    MyPluginType {}
}
--------------------

TL;DR:
    If I import my plugin module in Main.qml it works like a charm.
    If I dynamically create a qml object which call the same import call (import MyPlugin 1.0) it does not work. I get module MyPlugin is not installed.

In tried calling the registerTypes method inside initPlugin. This seems to work. But I am curious why it works if I call import in Main.qml and not in MyPluginButton.qml, and what I should do to make it work.


Have you tried debugging it with QML_IMPORT_TRACE? ;)


Generally I would recommend you take a different approach then "injecting" QML items into the engine (although this can be made to work, I guess).
A more flexible approach to extending an application like you plan to do is probably abstracting the actual functionality behind your button and only move that into the plugin (which by the way could be an actual Qt plugin that you can load with QPluginLoader).
Your application would at startup (or at runtime, both would be possible) then gather information about the available plugins and create a model, which you can pass to the UI to dynamically create buttons that map to functions in the plugins.




Thanks.

Kind regards,
Jesper


Regards
Martin





On 09-03-18 14:53, Jesper Huijgens wrote:
Ok, I see what the problem is.

I expected Qt to automatically register the types. Even without the import statement.

--
Jesper


On 09-03-18 14:44, Martin Leutelt wrote:


From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 2:24 PM
Subject: Re: [Interest] QQmlExtensionPlugin not loading


With QML_IMPORT_TRACE I see again the right folders. But I do not see any attempt of loading the plugin.


You're missing an import statement in your main.qml to load your plugin (see http://doc.qt.io/qt-5/qtqml-modules-cppplugins.html).
addPluginPath()/addLibraryPath() isn't necessary for QML plugins, but (depending on your project hierarchy or how your application is installed/deployed) you might need addImportPath().




Kind regards,
Jesper


Regards
Martin





On 09-03-18 14:20, Martin Leutelt wrote:


From: Jesper Huijgens <***@sioux.eu>
To: <***@qt-project.org>
Sent: 3/9/2018 2:04 PM
Subject: [Interest] QQmlExtensionPlugin not loading

Hi all,

For our project we see that QQmlExtensionPlugins are not loaded.
I made a very basic example project that creates a QQmlExtensionPlugin
and an application that should use. The plugin, with the corresponding
qmldir, are placed in a plugin subdir in the output directory of the
application.
The application sets both libraryPath and pluginPath. I output the
pluginPathList(), I see what I think are the correct folders on the
debug output.

I placed a qDebug() in registerTypes of the plugin. I see nothing on the
debug output.

Setting QT_DEBUG_PLUGINS to 1 show me a lot of libraries being loaded.
But not my plugin.




Try QML_IMPORT_TRACE instead, since QT_DEBUG_PLUGINS is for debugging plugins for Qt itself, not the QML engine.

I work on KDE Neon with g++ 5.4.0, CMake 3.10.0 and Qt 5.10.

Kind regards,
Jesper





Regards
Martin


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest




_______________________________________________
Interest mailing list
***@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Loading...