Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QML on Windows: MyComponent is not a type



  • Hello,

    I have a problem with QML on Windows that doesn't seem to be very common on the net. I'm using Qt 5.3.1.

    I'm using QtCreator for the project. I added some qml components through the IDE interface, and inspecting them on disk reveals that main.qml and all the other components it's loading are in the same directory.

    here's the problem:

    @engine.load(QUrl(QStringLiteral("qrc:///main.qml")));@

    QmlApplicationEngine failed to load component
    qrc:///main.qml:14 PlaylistOpenDialog is not a type

    PlaylistOpenDialog.qml is in the same directory as main.qml. QtCreator is actually auto-completing it's name when I type it.

    Now, there's that closed bug https://bugreports.qt-project.org/browse/QTBUG-26417 , which recommends that I use absolute paths. Ignoring the deployment issue of using an absolute path, I do not know how to specify it on Windows. If I write "qml:/D:\MyProject" for example, it doesn't work. It may be that Qt is mistaking D: as another protocol or something. Removing the colon doesn't help, either. I also tried replacing backward slashes with forward ones.

    So please, help me load this thing, using relative paths if possible.

    Thanks


  • Moderators

    I suspect Qt is having a trouble with the resource file. Try adding something like this to your main.qml:
    @
    import ":/"
    @



  • Thanks for your reply.

    I did that, and I get:

    qrc:///main.qml:3 ":/": no such directory


  • Moderators

    Try different combinations, like "qrc:/", "qrc:///", etc.

    Are those component files also in the same prefix (folder) in the QRC file? Maybe you have moved them somewhere else?



  • I tried "qrc:/" with both the import suggested and without. I don't get different results though.

    To assure that I have main.qml and PlayListOpenDialog.qml in the same folder, here's a screenshot of it https://www.dropbox.com/s/qqxifw2ora50yy7/all_in.png?dl=0 .

    Also, I have some other loaded components in main.qml. The component issued in the error message varies from a compilation to another. If that helps.


  • Moderators

    OK, they are physically in the same folder. But are they all in the same folder inside the QRC file?



  • Thanks, that worked.

    I added the components to qml.qrc file:

    @
    <file>main.qml</file>
    <file>PlaylistOpenDialog.qml</file>
    <file>PlaylistSaveDialog.qml</file>
    <file>TransferToDialog.qml</file>
    <file>AppMenuBar.qml</file>
    @

    It's strange that QtCreator didn't do that when I added them though.


  • Moderators

    [quote author="blueblood" date="1408955749"]It's strange that QtCreator didn't do that when I added them though.[/quote]

    Not really, resource files are an option, not a requirement in Qt (and QML).


Log in to reply