Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. "Unknown component. (M300)" for custom QML class
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 8 Posters 25.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PhrogzP Offline
    PhrogzP Offline
    Phrogz
    wrote on last edited by
    #1

    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:

    MyProject/
        main.qml
        CommonWidget.qml
        screens/
            Screen1.qml
    

    My .qrc looks like this:

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

    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.

    DiracsbracketD 1 Reply Last reply
    0
    • PhrogzP Phrogz

      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:

      MyProject/
          main.qml
          CommonWidget.qml
          screens/
              Screen1.qml
      

      My .qrc looks like this:

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

      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.

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by Diracsbracket
      #2

      @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...

      1 Reply Last reply
      0
      • PhrogzP Offline
        PhrogzP Offline
        Phrogz
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shaan7
          wrote on last edited by
          #4

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

          paghsaP T J e.sinohehE 4 Replies Last reply
          27
          • S shaan7

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

            paghsaP Offline
            paghsaP Offline
            paghsa
            wrote on last edited by
            #5

            @shaan7
            thanks this was really helpful

            1 Reply Last reply
            1
            • S shaan7

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

              T Offline
              T Offline
              Tom_Kruise
              wrote on last edited by
              #6

              @shaan7 This 2 mouse click solution worked for me, solving the head scratching problem of Qt Creator "unknown component (M300)" errors for ListModel and ListElement. Thanks.

              1 Reply Last reply
              1
              • E Offline
                E Offline
                equati0n
                wrote on last edited by
                #7

                @shaan7 Worked for me too. I was also having the problem of "unknown component (M300)" error for ListModel and ListElement. Thanks.

                1 Reply Last reply
                1
                • S shaan7

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

                  J Offline
                  J Offline
                  JsonYang
                  wrote on last edited by
                  #8

                  @shaan7 thanks!perfect solution!

                  1 Reply Last reply
                  1
                  • S shaan7

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

                    e.sinohehE Offline
                    e.sinohehE Offline
                    e.sinoheh
                    wrote on last edited by
                    #9

                    @shaan7 Works like magic

                    E.Sinoheh

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved