Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML import compatible with both Qt5 and Qt6

QML import compatible with both Qt5 and Qt6

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 153 Views 3 Watching
  • 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.
  • L Offline
    L Offline
    Likhitha_s
    wrote last edited by
    #1

    Hi,

    I want my QML code to run on both Qt 5.15 and Qt 6.

    Qt5: import QtQuick.Controls 2.15

    Qt6: import QtQuick.Controls

    Is there a way to write a single import statement that works on both, similar to how we do version checks in C++:

    #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
    // Qt6 code
    #else
    // Qt5 code
    #endif

    Thanks

    JKSHJ 1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote last edited by jeremy_k
      #2

      Including a version number in the import statement is still valid syntax in Qt 6.

      https://doc.qt.io/qt-6/qtqml-syntax-imports.html#module-namespace-imports

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Likhitha_s
        wrote last edited by
        #3

        https://doc.qt.io/qt-6/qtqml-syntax-imports.html#module-namespace-imports

        it says
        An example of an unqualified import with version would be

        import QtQuick 2.10

        In that case, any types defined in QtQuick 2.11 and higher or in any higher major version, like 6.0, would not be available to the file.

        jeremy_kJ SGaistS 2 Replies Last reply
        0
        • L Likhitha_s

          https://doc.qt.io/qt-6/qtqml-syntax-imports.html#module-namespace-imports

          it says
          An example of an unqualified import with version would be

          import QtQuick 2.10

          In that case, any types defined in QtQuick 2.11 and higher or in any higher major version, like 6.0, would not be available to the file.

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote last edited by
          #4

          @Likhitha_s said in QML import compatible with both Qt5 and Qt6:

          https://doc.qt.io/qt-6/qtqml-syntax-imports.html#module-namespace-imports

          it says
          An example of an unqualified import with version would be [...]

          Is there a question about this section of the documentation? I don't understand the purpose in repeating it without comment.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • L Likhitha_s

            https://doc.qt.io/qt-6/qtqml-syntax-imports.html#module-namespace-imports

            it says
            An example of an unqualified import with version would be

            import QtQuick 2.10

            In that case, any types defined in QtQuick 2.11 and higher or in any higher major version, like 6.0, would not be available to the file.

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote last edited by
            #5

            @Likhitha_s Hi,

            This comment just states that if you use versioned imports you will stay to that exact version.

            Since you want your code to work with both Qt 5 and Qt 6, it's in fact exactly what you want.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • L Likhitha_s

              Hi,

              I want my QML code to run on both Qt 5.15 and Qt 6.

              Qt5: import QtQuick.Controls 2.15

              Qt6: import QtQuick.Controls

              Is there a way to write a single import statement that works on both, similar to how we do version checks in C++:

              #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
              // Qt6 code
              #else
              // Qt5 code
              #endif

              Thanks

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote last edited by
              #6

              @Likhitha_s said in QML import compatible with both Qt5 and Qt6:

              Qt5: import QtQuick.Controls 2.15

              Qt6: import QtQuick.Controls

              You can use import QtQuick.Controls 2.15 for both Qt 5 and Qt 6.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              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