QML file from extension plugin -> "Unknown component"



  • Hi all,

    I still manage to build properly a custom QML lib, so I built an extension plugin.

    Everything works fine except...code completion within QtCreator. But it works during execution.

    My custom QML type (defined in a QML file, not a QML binding from C++) isn't recognized by the QML editor. It's very frustrating.

    I tried many things...it never works.

    Here's my project's structure :

    src
    -- app
    ---- some things
    ---- qml.qrc
    ------ main.qml // error M300
    -- libs
    ---- customquick // Folder of QML plugins
    ------ controls // my extension plugin
    -------- customquickcontrolsplugin.(h/cpp)
    -------- gridmenulogic.(h/cpp) // C++ binding class
    -------- GridMenu.qml // the type which isn't recognized in main.qml
    -------- qmldir

    My qmldir :
    @module customquick.controls
    GridMenu 1.0 GridMenu.qml
    plugin customquickcontrolsplugin
    classname CustomQuickControlsPlugin
    @

    main.qml
    @import QtQuick 2.2
    import QtQuick.Window 2.1
    import customquick.controls 1.0

    Window {
    visible: true
    width: 360
    height: 360

    GridMenu { *// <-- M300 error*
        id: menu
        anchors.fill: parent
    }
    

    }@

    GridMenu.qml
    @import QtQuick 2.0
    import customquick.controls 1.0

    Item {
    width: 100
    height: 80

    GridMenuLogic {
    
    }
    

    }
    @

    And my CustomQuickControlsPlugin class :
    @void CustomQuickControlsPlugin::registerTypes(const char *uri)
    {
    // @uri controls
    Q_ASSERT(uri == QLatin1String("customquick.controls"));
    qmlRegisterType<GridMenuLogic>(uri, 1, 0, "GridMenuLogic");
    }
    @

    The project copies the .qml files to the build directory and I setted the "QML2_IMPORT_PATH" environment var. But GridMenu is still underlined in main.qml...

    I works with QtCreator 3.2.0 and Ubuntu 14.04.

    Thanks for your help.



  • Hi,

    Did you try put this line in main.qml?
    #import GridMenuLogic 1.0

    []'s



  • Thanks for your reply.

    Yes, it doesn't work, the engine deosn't recognize it as a module.

    I tried to put GridMenu.qml in main.qml folder, and import with

    "import GridMenu.qml"

    but it failed too.



  • Well,

    Try to put GridMenu folder's path in a "import" clause, like this:

    main.qml:
    #import "../libs/customquick/controls".

    []'s



  • Well well well... It works...partially :p

    Firstly, I got a...warning (in french) :
    "The QML module contains some C++ modules, reading type informations...".

    So, GridMenu is recognized by the code model, but if I run the program it doesn't work anymore :

    "QQmlApplicationEngine failed to load component
    qrc:///main.qml:5 "../libs/customquick/controls": no such directory"

    Maybe because main.qml is within a Qt resource file ?

    EDIT : ok...it's because the qrc file. If I copy main.qml in the build directory and I delete it from the resource file, It works. The "import" is still yellow underlined.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.