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. Custom qml module import problem in QtCreator
Forum Updated to NodeBB v4.3 + New Features

Custom qml module import problem in QtCreator

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 5.1k Views 2 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.
  • Z Offline
    Z Offline
    Zeplinn
    wrote on last edited by
    #1

    I dont know if using a qmldir file is the right approach but it is only one i found that describe what i want to achieve.
    my goal is to be able to import my resuables components when importing them into one of my views *.qml by calling:

    import QSpin.Resuables 1.0 // qt creater designer should recognize this module
    

    So far i cant get it to work as i want.

    • When making a new qml file in my views folder and imports "QSpin.Resuables 1.0" qtCreator dosent recognize my components in the editor.
      -If i build and run my application it does so without any problems, but the editor still complains.
    • if i restart qt creator after the qml file has been created it now recognize my resuables components, however they do not require any import statement in order to be used.

    can any clarify how add a module structure proberly, or if there is a simpler way. I all ready looked through the documentation on this subject but so far i dont understand how to do it proberly
    my project structure:

    QSpin
    _ QSpin.pro
    _ headers
    __ .....
    _src
    __ .....
    _qml
    __reusables
    ___resuables.qrc
    ___qmldir
    ___( all qml files belonging to resuables.qrc and qmldir)
    __views
    ___views.qrc
    ___( all qml files belonging to views.qrc )

    QSpin.pro

    QT += quick qml gui quickcontrols2
    CONFIG += c++11
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
    	main.cpp \
        textgutter.cpp \
        QSpinStyle.cpp \
        QSpin.cpp \
        QsProject.cpp \
        CodeEditorHandler.cpp \
        QsError.cpp \
        VerificationMenuHandler.cpp \
        QsVerificationResults.cpp \
        Qs.cpp \
        EventAggregatorContainers.cpp
    
    RESOURCES += \
        qml/reusables/reusables.qrc \
        qml/views/views.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
        $$PWD/qml/reusables/qmldir
    
    #Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
        $$PWD/qml/reusables/qmldir
    
    HEADERS += \
        textgutter.h \
        QSpinStyle.h \
        QSpin.h \
        QsProject.h \
        IQsSerialization.h \
        CodeEditorHandler.h \
        QsError.h \
        VerificationMenuHandler.h \
        QsVerificationResults.h \
        eventaggregator.h \
        Qs.h \
        EventAggregatorContainers.h
    

    qmldir

    module QSpin.Reusables
    QsButton 1.0 QsButton.qml
    QsButtonSquare 1.0 QsButtonSquare.qml
    QsComboBox 1.0 QsComboBox.qml
    QsDivider 1.0 QsDivider.qml
    QsGroup 1.0 QsGroup.qml
    QsHeader 1.0 QsHeader.qml
    QsPane 1.0 QsPane.qml
    QsRadioIconButtons 1.0 QsRadioIconButtons.qml
    QsResultLabel 1.0 QsResultLabel.qml
    QsSpinBox 1.0 QsSpinBox.qml
    QsText 1.0 QsText.qml
    QsTextEdit 1.0 QsTextEdit.qml
    

    reusables.qrc

    <RCC>
        <qresource prefix="/">
            <file>QsPane.qml</file>
            <file>QsHeader.qml</file>
            <file>QsText.qml</file>
            <file>QsButton.qml</file>
            <file>QsTextEdit.qml</file>
            <file>QsSpinBox.qml</file>
            <file>QsComboBox.qml</file>
            <file>QsDivider.qml</file>
            <file>QsButtonSquare.qml</file>
            <file>QsRadioIconButtons.qml</file>
            <file>QsGroup.qml</file>
            <file>QsResultLabel.qml</file>
            <file>qmldir</file>
        </qresource>
    </RCC>
    

    views.qrc

    <RCC>
        <qresource prefix="/">
            <file>CodeEditor.qml</file>
            <file>qspin.qml</file>
            <file>SpinVerificationSettings.qml</file>
            <file>SpinVerifyConfig.qml</file>
            <file>VerificationMenu.qml</file>
            <file>QsSimulationTab.qml</file>
            <file>QsInteractiveView.qml</file>
            <file>GraphView.qml</file>
            <file>TestModuleImport.qml</file>
        </qresource>
    </RCC>
    
    
    raven-worxR 1 Reply Last reply
    0
    • Z Zeplinn

      I dont know if using a qmldir file is the right approach but it is only one i found that describe what i want to achieve.
      my goal is to be able to import my resuables components when importing them into one of my views *.qml by calling:

      import QSpin.Resuables 1.0 // qt creater designer should recognize this module
      

      So far i cant get it to work as i want.

      • When making a new qml file in my views folder and imports "QSpin.Resuables 1.0" qtCreator dosent recognize my components in the editor.
        -If i build and run my application it does so without any problems, but the editor still complains.
      • if i restart qt creator after the qml file has been created it now recognize my resuables components, however they do not require any import statement in order to be used.

      can any clarify how add a module structure proberly, or if there is a simpler way. I all ready looked through the documentation on this subject but so far i dont understand how to do it proberly
      my project structure:

      QSpin
      _ QSpin.pro
      _ headers
      __ .....
      _src
      __ .....
      _qml
      __reusables
      ___resuables.qrc
      ___qmldir
      ___( all qml files belonging to resuables.qrc and qmldir)
      __views
      ___views.qrc
      ___( all qml files belonging to views.qrc )

      QSpin.pro

      QT += quick qml gui quickcontrols2
      CONFIG += c++11
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      SOURCES += \
      	main.cpp \
          textgutter.cpp \
          QSpinStyle.cpp \
          QSpin.cpp \
          QsProject.cpp \
          CodeEditorHandler.cpp \
          QsError.cpp \
          VerificationMenuHandler.cpp \
          QsVerificationResults.cpp \
          Qs.cpp \
          EventAggregatorContainers.cpp
      
      RESOURCES += \
          qml/reusables/reusables.qrc \
          qml/views/views.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
          $$PWD/qml/reusables/qmldir
      
      #Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
          $$PWD/qml/reusables/qmldir
      
      HEADERS += \
          textgutter.h \
          QSpinStyle.h \
          QSpin.h \
          QsProject.h \
          IQsSerialization.h \
          CodeEditorHandler.h \
          QsError.h \
          VerificationMenuHandler.h \
          QsVerificationResults.h \
          eventaggregator.h \
          Qs.h \
          EventAggregatorContainers.h
      

      qmldir

      module QSpin.Reusables
      QsButton 1.0 QsButton.qml
      QsButtonSquare 1.0 QsButtonSquare.qml
      QsComboBox 1.0 QsComboBox.qml
      QsDivider 1.0 QsDivider.qml
      QsGroup 1.0 QsGroup.qml
      QsHeader 1.0 QsHeader.qml
      QsPane 1.0 QsPane.qml
      QsRadioIconButtons 1.0 QsRadioIconButtons.qml
      QsResultLabel 1.0 QsResultLabel.qml
      QsSpinBox 1.0 QsSpinBox.qml
      QsText 1.0 QsText.qml
      QsTextEdit 1.0 QsTextEdit.qml
      

      reusables.qrc

      <RCC>
          <qresource prefix="/">
              <file>QsPane.qml</file>
              <file>QsHeader.qml</file>
              <file>QsText.qml</file>
              <file>QsButton.qml</file>
              <file>QsTextEdit.qml</file>
              <file>QsSpinBox.qml</file>
              <file>QsComboBox.qml</file>
              <file>QsDivider.qml</file>
              <file>QsButtonSquare.qml</file>
              <file>QsRadioIconButtons.qml</file>
              <file>QsGroup.qml</file>
              <file>QsResultLabel.qml</file>
              <file>qmldir</file>
          </qresource>
      </RCC>
      

      views.qrc

      <RCC>
          <qresource prefix="/">
              <file>CodeEditor.qml</file>
              <file>qspin.qml</file>
              <file>SpinVerificationSettings.qml</file>
              <file>SpinVerifyConfig.qml</file>
              <file>VerificationMenu.qml</file>
              <file>QsSimulationTab.qml</file>
              <file>QsInteractiveView.qml</file>
              <file>GraphView.qml</file>
              <file>TestModuleImport.qml</file>
          </qresource>
      </RCC>
      
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Zeplinn said in Custom qml module import problem in QtCreator:

      QML_IMPORT_PATH

      this variable should actually contain the path from where the import of QSpin.Resuables can be found.
      This path should contain a folder QSpin and this folder then should contain an folder named Resuables. In there you place the qmldir file and the corresponding qml file.

      If i build and run my application it does so without any problems, but the editor still complains.

      But since your application runs fine, i wonder how you deploy your custom import then?
      Somehow this import must be accessible (the way i mentioned above) from the target application.

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

      Z 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @Zeplinn said in Custom qml module import problem in QtCreator:

        QML_IMPORT_PATH

        this variable should actually contain the path from where the import of QSpin.Resuables can be found.
        This path should contain a folder QSpin and this folder then should contain an folder named Resuables. In there you place the qmldir file and the corresponding qml file.

        If i build and run my application it does so without any problems, but the editor still complains.

        But since your application runs fine, i wonder how you deploy your custom import then?
        Somehow this import must be accessible (the way i mentioned above) from the target application.

        Z Offline
        Z Offline
        Zeplinn
        wrote on last edited by
        #3

        @raven-worx
        let me see if i understand you correctly.

        my project structure should be:

        QSpin
        _QSpin.pro
        _QSpin
        __Reusables
        ___qmldir
        ___ ( qml files)
        

        QSpin.pro

        QML_IMPORT_PATH +=\
            QSpin/Reusables/qmldir
        // or
           QSpin/Reusables
        

        Should i still have reusables.qrc in QSpin/Reusables, should it be in the root project folder, should it be registered in QSpin.pro or do i even need at all now?

        based on what u say about the folder structure, what is then the purpose in my qmldir file of declareing

        module QSpin.Reusables 1.0
        

        thank you for your reply

        raven-worxR 1 Reply Last reply
        0
        • Z Zeplinn

          @raven-worx
          let me see if i understand you correctly.

          my project structure should be:

          QSpin
          _QSpin.pro
          _QSpin
          __Reusables
          ___qmldir
          ___ ( qml files)
          

          QSpin.pro

          QML_IMPORT_PATH +=\
              QSpin/Reusables/qmldir
          // or
             QSpin/Reusables
          

          Should i still have reusables.qrc in QSpin/Reusables, should it be in the root project folder, should it be registered in QSpin.pro or do i even need at all now?

          based on what u say about the folder structure, what is then the purpose in my qmldir file of declareing

          module QSpin.Reusables 1.0
          

          thank you for your reply

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

          @Zeplinn:

          my project structure should be:
          QSpin
          _QSpin.pro
          _QSpin
          __Reusables
          ___qmldir
          ___ ( qml files)

          based on this structure:

          QML_IMPORT_PATH +=\
              $$PWD
          

          Should i still have reusables.qrc in QSpin/Reusables, should it be in the root project folder, should it be registered in QSpin.pro or do i even need at all now?

          The qrc is only relevant during build-time, you can place it where ever you want.

          based on what u say about the folder structure, what is then the purpose in my qmldir file of declareing
          module QSpin.Reusables 1.0

          See this.
          Also there shouldn't be any versioning in this line.

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

          Z 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @Zeplinn:

            my project structure should be:
            QSpin
            _QSpin.pro
            _QSpin
            __Reusables
            ___qmldir
            ___ ( qml files)

            based on this structure:

            QML_IMPORT_PATH +=\
                $$PWD
            

            Should i still have reusables.qrc in QSpin/Reusables, should it be in the root project folder, should it be registered in QSpin.pro or do i even need at all now?

            The qrc is only relevant during build-time, you can place it where ever you want.

            based on what u say about the folder structure, what is then the purpose in my qmldir file of declareing
            module QSpin.Reusables 1.0

            See this.
            Also there shouldn't be any versioning in this line.

            Z Offline
            Z Offline
            Zeplinn
            wrote on last edited by
            #5

            @raven-worx
            thank you very much for your time.
            I found a solution which works as intended now.
            the import path however is now

            import QSpin.qml.reusables 1.0 
            // Dont know if import default to 1.0 if version in qmldir is left out. 
            / It does work when including version
            

            qmldir

            module QSpin.qml.reusables #It needs to follow the folder path after the QML_IMPORT_PATH
            
            # Additional import path used to resolve QML modules in Qt Creator's code model
            QML_IMPORT_PATH += \
                $$PWD/../
            
            # Additional import path used to resolve QML modules just for Qt Quick Designer
            QML_DESIGNER_IMPORT_PATH += \
                $$PWD/../
            

            the reusable.qrc must not be located in the same folder as the qml files or qtcreator seems to act up in its auto completion.
            I finally found an example i understood.
            I followed this example

            adding the version was a brain fart.

            Thank you very much for your help.

            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