Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QML parsing errors, from not included qml files

QML parsing errors, from not included qml files

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 2 Posters 423 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.
  • J.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on last edited by J.Hilk
    #1

    So I have a "QML library" that is used in different projects, those themselves can be compiled with Qt5 or Qt6.

    For that reason I was forced to split some files into Qt5 and Qt6 files and load them dynamically via a Loader component. Annoying but not unreasonable.

    Compiling for Qt6 works perfectly fine, but for Qt5 I get the following "error":

    /Users/.../Qt-Projekte/.../Dependencies/SharedFiles/qml/Dialogs/Base/FileDialogQt6.qml:2: error: package import requires a version number

    I could get around it by explicitly giving the Qt6 imports version numbers, but AFAIK it is no longer considered good behaviour to do so in Qt6

    so I had the following bright idea:

    //pri file to include in other projects
    RESOURCES ''+= \
        $$PWD/img.qrc \
        $$PWD/sharedQml.qrc
    
    contains(QT_MAJOR_VERSION, 5) {
        RESOURCES += $$PWD/sharedQmlQt5.qrc
    } else {
        RESOURCES += $$PWD/sharedQmlQt6.qrc
    }
    
    //sharedQmlQt5.qrc
    <RCC>
        <qresource prefix="/Dependencies/SharedFiles">
            <file>qml/Dialogs/Base/FileDialogQt5.qml</file>
            <file>qml/Dialogs/Base/FolderDialogQt5.qml</file>
            <file>qml/Dialogs/Base/MessageDialogQt5.qml</file>
            <file>qml/Dialogs/Base/SaveFileDialogQt5.qml</file>
        </qresource>
    </RCC>
    
    //sharedQmlQt6.qrc
    <RCC>
        <qresource prefix="/Dependencies/SharedFiles">
            <file>qml/Dialogs/Base/FileDialogQt6.qml</file>
            <file>qml/Dialogs/Base/FolderDialogQt6.qml</file>
            <file>qml/Dialogs/Base/MessageDialogQt6.qml</file>
        </qresource>
    </RCC>
    

    The sharedQmlQt6.qrc is greyed out inside QtCreator, but the error: package import requires a version number does not disappear.

    Compiling and running is completely fine. But the error-tab has errors in it.

    commenting the rsc out, works but is not a robust and elegant solution either.

    RESOURCES ''+= \
        $$PWD/img.qrc \
        $$PWD/sharedQml.qrc
    
    contains(QT_MAJOR_VERSION, 5) {
        RESOURCES += $$PWD/sharedQmlQt5.qrc
    } else {
        # RESOURCES += $$PWD/sharedQmlQt6.qrc
    }
    

    Any suggestions, besides adding the version number in the Qt6 files :D ?


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    jeremy_kJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      So I have a "QML library" that is used in different projects, those themselves can be compiled with Qt5 or Qt6.

      For that reason I was forced to split some files into Qt5 and Qt6 files and load them dynamically via a Loader component. Annoying but not unreasonable.

      Compiling for Qt6 works perfectly fine, but for Qt5 I get the following "error":

      /Users/.../Qt-Projekte/.../Dependencies/SharedFiles/qml/Dialogs/Base/FileDialogQt6.qml:2: error: package import requires a version number

      I could get around it by explicitly giving the Qt6 imports version numbers, but AFAIK it is no longer considered good behaviour to do so in Qt6

      so I had the following bright idea:

      //pri file to include in other projects
      RESOURCES ''+= \
          $$PWD/img.qrc \
          $$PWD/sharedQml.qrc
      
      contains(QT_MAJOR_VERSION, 5) {
          RESOURCES += $$PWD/sharedQmlQt5.qrc
      } else {
          RESOURCES += $$PWD/sharedQmlQt6.qrc
      }
      
      //sharedQmlQt5.qrc
      <RCC>
          <qresource prefix="/Dependencies/SharedFiles">
              <file>qml/Dialogs/Base/FileDialogQt5.qml</file>
              <file>qml/Dialogs/Base/FolderDialogQt5.qml</file>
              <file>qml/Dialogs/Base/MessageDialogQt5.qml</file>
              <file>qml/Dialogs/Base/SaveFileDialogQt5.qml</file>
          </qresource>
      </RCC>
      
      //sharedQmlQt6.qrc
      <RCC>
          <qresource prefix="/Dependencies/SharedFiles">
              <file>qml/Dialogs/Base/FileDialogQt6.qml</file>
              <file>qml/Dialogs/Base/FolderDialogQt6.qml</file>
              <file>qml/Dialogs/Base/MessageDialogQt6.qml</file>
          </qresource>
      </RCC>
      

      The sharedQmlQt6.qrc is greyed out inside QtCreator, but the error: package import requires a version number does not disappear.

      Compiling and running is completely fine. But the error-tab has errors in it.

      commenting the rsc out, works but is not a robust and elegant solution either.

      RESOURCES ''+= \
          $$PWD/img.qrc \
          $$PWD/sharedQml.qrc
      
      contains(QT_MAJOR_VERSION, 5) {
          RESOURCES += $$PWD/sharedQmlQt5.qrc
      } else {
          # RESOURCES += $$PWD/sharedQmlQt6.qrc
      }
      

      Any suggestions, besides adding the version number in the Qt6 files :D ?

      jeremy_kJ Online
      jeremy_kJ Online
      jeremy_k
      wrote on last edited by
      #2

      @J-Hilk said in QML parsing errors, from not included qml files:

      So I have a "QML library" that is used in different projects, those themselves can be compiled with Qt5 or Qt6.

      For that reason I was forced to split some files into Qt5 and Qt6 files and load them dynamically via a Loader component. Annoying but not unreasonable.

      This sounds like the problem class QFileSelector is intended to solve, even if it doesn't include a Qt version selector automatically. A single #ifdef when setting up the QML engine sounds better to me than multiple loaders.

      Alas, I don't know if Creator will recognize non-default (or default) selectors.

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

      J.HilkJ 1 Reply Last reply
      1
      • jeremy_kJ jeremy_k

        @J-Hilk said in QML parsing errors, from not included qml files:

        So I have a "QML library" that is used in different projects, those themselves can be compiled with Qt5 or Qt6.

        For that reason I was forced to split some files into Qt5 and Qt6 files and load them dynamically via a Loader component. Annoying but not unreasonable.

        This sounds like the problem class QFileSelector is intended to solve, even if it doesn't include a Qt version selector automatically. A single #ifdef when setting up the QML engine sounds better to me than multiple loaders.

        Alas, I don't know if Creator will recognize non-default (or default) selectors.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @jeremy_k interesting! Thank you I knew of QFileSelector, but I have never used it and not thought of it.

        In the documentation its nowhere said, that
        There's also QQmlFileSelector and QQmlApplicationEngine also comes with an instance backed in with a preset selector (for me in this case) of ("en_DE", "unix", "darwin", "mac", "osx", "macos")

        I assume I would simply add my qtversion selection:

        QQmlApplicationEngine engine;
            
           auto qsel = QQmlFileSelector::get(&engine);
            #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
                qsel->setExtraSelectors({"qt6"});
            #else
                qsel->setExtraSelectors({"qt5"});
            #endif
        
            engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
        

        I could than forgo with the loader, if I adjusted my folder structure
        from:

        - Dialogs
          - SaveFileDialog.qm 
            - Base
              - SaveFileDialogQt5.qml //Dialogs/Base/SaveFileDialogQt5.qml
              - SaveFileDialogQt6.qml //Dialogs/Base/SaveFileDialogQt6.qml
        

        to:

        - Dialogs
          - SaveFileDialog.qm //Default selection, possibly empty?
            - qt5
              - SaveFileDialog.qml //Dialogs/+qt5/SaveFileDialog.qml
            - qt6
              - SaveFileDialog.qml //Dialogs/+qt6/SaveFileDialog.qml
        

        Probably the more elegant solution, and totally what I was originally looking for, before I decided on Loaders! . But I still would need to have all files as part of my resource system qrc:/

        <RCC>
        <qresource prefix="/Dependencies/SharedFiles">
        <file>qml/Dialogs/SaveFileDialog.qml </file>
        <file>qml/Dialogs/+qt5/SaveFileDialog.qml</file>
        <file>qml/Dialogs/+qt6/SaveFileDialog.qml</file>
        </qresource>
        </RCC>

        I don't think this is going to solve my original problem.
        Like I said, the "errors" only disappear when I remove them from my project file(*.pro) altogether.

        But I will try, I think


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0
        • J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          So QQmlFileSelector does work, makes it that much cleaner and easier to use.
          But in my case, it's actually worse, previously the Qt6 Qml would cause those error messages in the issue tab, but the program would compile and launch, now it doesn't launch.

          I tripple checked, the loader works fine, but produces the same errors, but those errors then do not trigger an abort of the compilation.

          It does eventually compile, if I explicitly disable the QtQuickCompiler, which is not ideal.

          Anyway I'm back to square one :D

          Maybe I should open a bug report, the error should not be there, if it's not an actual error. On the other hand, the change to Qt6 is inevitable.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • jeremy_kJ Online
            jeremy_kJ Online
            jeremy_k
            wrote on last edited by
            #5

            That's unfortunate. I have a vague recollection of a similar problem with the Quick compiler.

            Build-time selection such as per-Qt version resource files might work.

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

            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