Qt Creator doesn't see qml types in locally intalled qml molule



  • I've created my project which consists of main.cpp, main.qml and module in some other local directory which I want to import.
    My application builds and works well.
    But Qt Creator doesn't see types from module and accentuates

    import MyModule 1.0

    in main.qml file with red line.

    How is it possible to make my module visible to Qt Creator?



  • Hi! Let's say your module is named "MyControls". And let's assume your application get's installed to
    install-root/bin/myapp.exe. You must then put your module in a sub-directory with the exact same name, here: install-root/bin/MyControls/. And you need the following files to be installed into that directory:

    MyControls.dll // compiled shared object part of the module
    SomeItem.qml 
    AnotherItem.qml
    qmldir // special file
    plugins.qmltypes // special file
    

    The qmldir file has to look like this:

    module MyControls
    plugin MyControls
    SomeItem 1.0 SomeItem.qml
    AnotherItem 1.0 AnotherItem.qml
    

    And the file plugins.qmltypes must be generated with qmlplugindump (see Generating qmltypes Files).

    And finally you need to tell Qt Creator where to find your module, by adding the directory to the QML module import path variable. With Qbs you can skip that last part and just add the following to your .qbs file:

        property string qmlImportPaths: "/blah/foo/bar/install-root/bin"
    

    And, yes, it's complicated ;-)



  • Great thank for your answer!

    Could you please explain what is plugin MyControls and MyControls.dll? Is it C++ plugin?
    And how to say Qt Creator about path where it is necessary to fing module? I included this path into INCLUDEPATH variable. But it didn't work.
    My application builds and works well. But when I edit code Qt Creator doesn't recognize types from module. Application runs well despite of it.



  • Could you please explain what is plugin MyControls and MyControls.dll? Is it C++ plugin?

    Yes, exactly. You can find in-depth info in Creating C++ Plugins for QML, and there is also an example: QML Plugin Example.

    And how to say Qt Creator about path (...) ?

    You need to add the path that contains your module-directory to the QML2_IMPORT_PATH environment variable. The easiest place to do that is in project settings > run environment:

    QML2_IMPORT_PATH = /blah/foo/bar/install-root/



  • Unfortunetely It doen't work.

    This is my project settings

    0_1490978725030_upload-2c6bb35f-e15c-4106-97f5-82c8565c1a67
    This is my main.qml
    0_1490978772590_upload-25731136-9755-48f8-a430-586c08fb85b7

    This is project directory:
    0_1490978815555_upload-3ee90741-06a5-43cd-8a72-e0ca8f3575fc

    This is MyModule directory:
    0_1490978975388_upload-e5f2119a-6a94-44ad-8f1d-e112f5233560

    And this is qmldir file:
    0_1490978888706_upload-4d3cbcb4-2699-4ca5-a6a7-9dd30125e3ac

    What is wrong?


Log in to reply
 

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