Qt World Summit: Register Today!

"Unknown component. (M300)" for custom QML class

  • Summary: Referencing my custom QML widget that is in a different directory results in Qt Creator highlighting it as an error, flagged with the message "Unknown component. (M300)". However, the QML resolves correctly at runtime without error. How can I fix Qt Creator to not act like a dunce?

    I have this physical directory structure:


    My .qrc looks like this:

        <qresource prefix="/">
            <file alias="Screen1.qml">screens/Screen1.qml</file>

    Inside of Screen1.qml the code is roughly:

    import QtQuick 2.6
    Item {
        CommonWidget { /* ...content here... */ }              // Error: Unknown component. (M300)
        // other stuff

    Per this StackOverflow answer I tried adding import "../screens" to my QML, but that did not change Qt Creator's behavior.

  • @Phrogz
    Why add import "../screens" in Screen1.qml, since CommonWidget.qml is defined in the parent directory of the screens directory?

    To use CommonWidget in Screen1.qml, you can use :

    import ".."

    Otherwise, if all is correct, you may need to re-run qmake first to get QtCreator to recognize the new component after adding the file to the project...

  • The problem goes away and shows up again as I add new QML. The import statement is unnecessary. The (surely overkill) steps I've used to fix it:

    1. Quit Qt Creator
    2. Delete all output directories from disk
    3. Delete the .pro.user file.
    4. Launch Qt Creator and re-open the project (re-setting up the .pro.user in the process).

    When I do those steps, this problem always goes away.

  • Did you try Tools > QML/JS > Reset Code Model? Usually works for me.

  • @shaan7
    thanks this was really helpful

Log in to reply