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. QML QDoc: inheritance, import statement and qmlmodule
Forum Update on Monday, May 27th 2025

QML QDoc: inheritance, import statement and qmlmodule

Scheduled Pinned Locked Moved Solved QML and Qt Quick
crea
10 Posts 2 Posters 535 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.
  • T Offline
    T Offline
    The friendly stranger
    wrote on last edited by
    #1

    Hi everyone,

    I made a library of QML controls with Visual Studio 2019 (so I am not using Qt Creator).
    I want to make a documentation with the QDoc. I am able to generate a documentation that works but I still have some issues.

    • I want to display the "inherits" and "inherited by" like QtQuick does:

    9d4ad070-f821-463d-b38f-bdfeefa7405f-image.png

    This works fine if I only use controls from my library (MyItem1 and MyItem2). However, there is no display if the parent is a QtQuick control (Item.qml, Rectangle.qml...). Nothing changes if I use \inherits and QtQuick namespace (ex: QtQuick::Item). Any idea what the problem is ?

    • I want to display the Import Statement like any control in the qml documentation. Unfortunnately, the import is weird (see below)
      9b872f57-2b90-49c1-9c9f-93882fff1af0-image.png
      I just don't know how to handle this part. I understand I may have to use qdoc and define a qmlmodule. But I don't know how to link my qdoc to my qdocconfig. I don't have any error nor result in the doc. I have the feeling that I'll have to make a .pro file but I don't use QtCreator...

    Below a minimal version of my code:

    DocQML.qdocconf

    include($QTDIR/doc/global/compat.qdocconf)
    include($QTDIR/doc/global/qt-cpp-defines.qdocconf)
    
    project = MyProject
    version = 1.0.0.0
    description = Documentation for my controls.
    
    sourcedirs = ../qml/
    headerdirs = ../qml/
    imagedirs = .
    
    sources.fileextensions = "*.qdoc *.qml"
    
    outputdir  =    ./doc/qml/
    outputformats = HTML
    
    HTML.stylesheets = style.css
    HTML.headerstyles = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\"/>\n"
    

    mymodule.qdoc - This file has no impact on the doc

    /*!
        \qmlmodule MyLib 1.0
        \title MyLib 1.0 QML types
    
        This is my lib
    */
    

    MyItem1 - inheritance doesn't work

    import QtQuick 2.10 as QtQuick
    
    /*!
    	\qmltype MyItem1
    	\inqmlmodule MyLib
    	\inherits QtQuick::Item
    	A custom item 1. MyLib. MyLib::MyItem2
    */
    
    QtQuick.Item { /* */}
    

    MyItem2 - inheritance works since I use my local control

    import QtQuick 2.10  as QtQuick
    
    /*!
    	\qmltype MyItem2
    	\inqmlmodule MyLib
    
    	 A custom item 2
    */
    
    QtQuick.MyItem1 { /**/}
    
    raven-worxR 1 Reply Last reply
    0
    • T The friendly stranger

      Hi everyone,

      I made a library of QML controls with Visual Studio 2019 (so I am not using Qt Creator).
      I want to make a documentation with the QDoc. I am able to generate a documentation that works but I still have some issues.

      • I want to display the "inherits" and "inherited by" like QtQuick does:

      9d4ad070-f821-463d-b38f-bdfeefa7405f-image.png

      This works fine if I only use controls from my library (MyItem1 and MyItem2). However, there is no display if the parent is a QtQuick control (Item.qml, Rectangle.qml...). Nothing changes if I use \inherits and QtQuick namespace (ex: QtQuick::Item). Any idea what the problem is ?

      • I want to display the Import Statement like any control in the qml documentation. Unfortunnately, the import is weird (see below)
        9b872f57-2b90-49c1-9c9f-93882fff1af0-image.png
        I just don't know how to handle this part. I understand I may have to use qdoc and define a qmlmodule. But I don't know how to link my qdoc to my qdocconfig. I don't have any error nor result in the doc. I have the feeling that I'll have to make a .pro file but I don't use QtCreator...

      Below a minimal version of my code:

      DocQML.qdocconf

      include($QTDIR/doc/global/compat.qdocconf)
      include($QTDIR/doc/global/qt-cpp-defines.qdocconf)
      
      project = MyProject
      version = 1.0.0.0
      description = Documentation for my controls.
      
      sourcedirs = ../qml/
      headerdirs = ../qml/
      imagedirs = .
      
      sources.fileextensions = "*.qdoc *.qml"
      
      outputdir  =    ./doc/qml/
      outputformats = HTML
      
      HTML.stylesheets = style.css
      HTML.headerstyles = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\"/>\n"
      

      mymodule.qdoc - This file has no impact on the doc

      /*!
          \qmlmodule MyLib 1.0
          \title MyLib 1.0 QML types
      
          This is my lib
      */
      

      MyItem1 - inheritance doesn't work

      import QtQuick 2.10 as QtQuick
      
      /*!
      	\qmltype MyItem1
      	\inqmlmodule MyLib
      	\inherits QtQuick::Item
      	A custom item 1. MyLib. MyLib::MyItem2
      */
      
      QtQuick.Item { /* */}
      

      MyItem2 - inheritance works since I use my local control

      import QtQuick 2.10  as QtQuick
      
      /*!
      	\qmltype MyItem2
      	\inqmlmodule MyLib
      
      	 A custom item 2
      */
      
      QtQuick.MyItem1 { /**/}
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @The-friendly-stranger

      import statement

      I can confirm that using the following in an arbitrary qdoc file displays a correct import statement in the docs:

      /*!
          \qmlmodule My.Module 1.0
          \title My QML module
          \brief Some of my components
      
          Description of my module
      */
      

      Where did you place mymodule.qdoc? It needs to be inside a folder you referenced in DocQML.qdocconf in sourcedirs. E.g:

      sourcedirs += \
           ../qml/ \
           path/to/qdoc/files/
      

      Inherits statement

      Since you want to reference / link against Qt types in the docs you are missing the index files which have the necessary doc information for Qt types. In your DocQML.qdocconf add something like this:

      indexes += \
            indexes/qtqml.index \
            indexes/qtquick.index \
            indexes/qtquickcontrols.index \
            indexes/qtquickcontrols2.index \
            ... \
            ...
      

      The index files of each module can be found in your Qt installation. E.g. "C:\Qt\Docs\Qt-5.15.2\qtquick\qtquick.index"

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • T Offline
        T Offline
        The friendly stranger
        wrote on last edited by The friendly stranger
        #3

        import statement
        Aaaah thank you! Of course I need to specify the right path... I put the .qdoc with my .qdocconf but I didn't add the current path to sourcedirs. Now it works well

        Inherits statement
        Your explanation are very clear but I didn't find any .index in my Qt folder. I went to the doc folder and I only found qdocconf and qdoc files (See the image below).
        1c8be48d-c320-46ce-8fee-b1ae992bc363-image.png
        I also tried to generate a doc with the qt-module-default.qdocconf but I have missing environment variables. I read the documentation about the indexes and found the keyword "depends'' but no success. As you can see on the picture, I use Qt 5.10 with msvc2017.

        Thanks again for all your help.

        raven-worxR 1 Reply Last reply
        0
        • T The friendly stranger

          import statement
          Aaaah thank you! Of course I need to specify the right path... I put the .qdoc with my .qdocconf but I didn't add the current path to sourcedirs. Now it works well

          Inherits statement
          Your explanation are very clear but I didn't find any .index in my Qt folder. I went to the doc folder and I only found qdocconf and qdoc files (See the image below).
          1c8be48d-c320-46ce-8fee-b1ae992bc363-image.png
          I also tried to generate a doc with the qt-module-default.qdocconf but I have missing environment variables. I read the documentation about the indexes and found the keyword "depends'' but no success. As you can see on the picture, I use Qt 5.10 with msvc2017.

          Thanks again for all your help.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @The-friendly-stranger
          as i said the index files are for example in "C:\Qt\Docs\Qt-5.12.5\qtquick\qtquick.index"
          Where the platform Qt data is in "C:\Qt\5.12.5\msvc2017_64..."

          So i guess you are looking the wrong sub folder.
          Simply search for "*.index" files in the path containing your Qt MaintainanceTool

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • T Offline
            T Offline
            The friendly stranger
            wrote on last edited by The friendly stranger
            #5

            There is no such .index file in the entire Qt folder. I use a binaries version so I am wondering if some files are missing.
            Is there any way to get/generate the .html and the .index myself ?

            Otherwise, is it possible to use the \inherits with a link ? So I can redirect the users on the Qt webpage.

            raven-worxR 1 Reply Last reply
            0
            • T The friendly stranger

              There is no such .index file in the entire Qt folder. I use a binaries version so I am wondering if some files are missing.
              Is there any way to get/generate the .html and the .index myself ?

              Otherwise, is it possible to use the \inherits with a link ? So I can redirect the users on the Qt webpage.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @The-friendly-stranger said in QML QDoc: inheritance, import statement and qmlmodule:

              Is there any way to get/generate the .html and the .index myself

              build the docs from Qt source yourself
              Or use the MaintainanceTool and just download the documentation.

              Make sure you call it with MaintenanceTool.exe --show-virtual-components and then just checkmark the documentaion

              Otherwise, is it possible to use the \inherits with a link ? So I can redirect the users on the Qt webpage.

              thats what the index files are there for.
              if you build your docs with an online template you get online ref links, for offline docs (e.g. inside QtCreator) you get ref links there.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • T Offline
                T Offline
                The friendly stranger
                wrote on last edited by
                #7

                Thanks again for your help! The inheritance works well with the items from QtQuick.
                However, I have a corner case with the QtQuickControls module.

                Sometimes, my control shares the same name than Qt. For instance, I have my own CheckBox that inherits from Qt CheckBox.

                // CheckBox.qml - My slider
                import QtQuick 2.10
                import QtQuick.Controls 2.3 as QtQuickControls
                QtQuickControls.CheckBox {
                // ...
                }
                

                In this case, I am unable to show the CheckBox parent.

                This is weird because I don't have this issue with the QtQuick module. As a test, I made my own Canvas control that inherits from Qt Canvas and I have the right reference.

                // Canvas.qml - My canvas
                import QtQuick 2.10
                Canvas {
                // ...
                }
                

                2fada03a-93cc-4acf-8093-24bfb15ee414-image.png

                I can also make the difference between the 2 Canvas using MyModule::Canvas and QtQuick::Canvas. MyModule::CheckBox works but I didn't find the right namespace for the Qt version. I tried QtQuick/QtQuickControls/QtQuickControls2 with several case combinaisons.

                I guess the best advice is not using the same name than Qt but I would like to keep them, if possible.

                Once again, thank you very much for all your help.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  The friendly stranger
                  wrote on last edited by The friendly stranger
                  #8

                  I will edit my previous message.

                  I didn't have the Checkbox inheritance from Qt because I used the modules qtquickcontrols.index and qtquickcontrols2.index at the same time. I guess there was a conflict between these files. Now it works if I only use qtqml.index, qtquick.index and qtquickcontrols2.index.

                  I still have the issue with the namespace though. I cannot use the CheckBox from QtQuickControls.

                  Here my current file with the indexes.

                  project = MyModule
                  version = 1.0.0.0
                  description = Documentation for MyModule
                  
                  sourcedirs = \
                  	./ \
                  	../qml/ \
                  	
                  headerdirs = ../qml/
                  imagedirs = .
                  
                  indexes = \
                  	Qt/qtqml/qtqml.index \
                  	Qt/qtquick/qtquick.index \
                  	Qt/qtquickcontrols2/qtquickcontrols2.index
                  
                  sources.fileextensions = "*.qml *.qdoc"
                  
                  outputdir  =    ./generated/
                  outputformats = HTML
                  
                  HTML.stylesheets = style.css
                  HTML.headerstyles = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\"/>\n"
                  
                  raven-worxR 1 Reply Last reply
                  0
                  • T The friendly stranger

                    I will edit my previous message.

                    I didn't have the Checkbox inheritance from Qt because I used the modules qtquickcontrols.index and qtquickcontrols2.index at the same time. I guess there was a conflict between these files. Now it works if I only use qtqml.index, qtquick.index and qtquickcontrols2.index.

                    I still have the issue with the namespace though. I cannot use the CheckBox from QtQuickControls.

                    Here my current file with the indexes.

                    project = MyModule
                    version = 1.0.0.0
                    description = Documentation for MyModule
                    
                    sourcedirs = \
                    	./ \
                    	../qml/ \
                    	
                    headerdirs = ../qml/
                    imagedirs = .
                    
                    indexes = \
                    	Qt/qtqml/qtqml.index \
                    	Qt/qtquick/qtquick.index \
                    	Qt/qtquickcontrols2/qtquickcontrols2.index
                    
                    sources.fileextensions = "*.qml *.qdoc"
                    
                    outputdir  =    ./generated/
                    outputformats = HTML
                    
                    HTML.stylesheets = style.css
                    HTML.headerstyles = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\"/>\n"
                    
                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @The-friendly-stranger
                    https://doc.qt.io/qt-5/08-qdoc-commands-creatinglinks.html#fixing-ambiguous-links

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      The friendly stranger
                      wrote on last edited by
                      #10

                      Ok I see, I will take a closer look on this. Thank you for all your help. I will mark this discussion as resolved

                      1 Reply Last reply
                      0

                      • Login

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