Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113577

Adding an example to the implicit import section

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.5.0
    • Documentation
    • None
    • All

      doc link : https://doc.qt.io/qt-6/qtqml-syntax-directoryimports.html#the-implicit-import

      I think for the Note, we should add the following example to make it clear.
      *This is my interpretation of what's written. Please correct it accordingly.

      ----------------------

       

      Let's say the directory is structured as follows.
      
      project_dir
      |-a.qml
      |-qmldir
      |-subdir
         |-b.qml
         |-c.qml
      
      This is a bad case. The qmldir defines a module contains b.qml and c.qml and c.qml is declared as singleton. The a.qml imports this module.
      What happens is in a.qml, c.qml is correctly treated as singleton, but b.qml, which implicitly imports c.qml in the same directory, doesn't treat c.qml as a singleton. Therefore, c.qml is treated as singleton in one place but not in the other.
      
      However, in this good example below, in both a.qml and b.qml, c.qml is treated as singleton, because a.qml imports a module defined in qmldir, so that it's aware of the fact that c.qml is declared as singleton. Also since b.qml is aware of the qmldir in the same directory, it automatically treats c.qml as singleton too. As a result, c.qml is treated as singleton in all the places it's used.
      
      project_dir
      |-a.qml
      |-subdir
         |- b.qml
         |- c.qml
         |-qmldir
      
      
       

       

       
       

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            docteam Qt Documentation Team
            mikio_hirai Mikio Hirai
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes