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. issues with using qt_policy(SET QTP0001 NEW)
Forum Updated to NodeBB v4.3 + New Features

issues with using qt_policy(SET QTP0001 NEW)

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 2 Posters 4.2k 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.
  • JKSHJ JKSH

    @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

    import Colors
    

    You must import the URI as specified in the qt_add_qml_module() function that contains Colors.qml

    mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #9

    @JKSH said in issues with using qt_policy(SET QTP0001 NEW):

    You must import the URI as specified in the qt_add_qml_module() function that contains Colors.qml

    My function reads as:

    qt_add_qml_module(appnga_demo
        URI nga_demo
        VERSION 1.0
        QML_FILES
        (other files)
        Colors.qml
        (other files)
    

    I don't know what you mean by "import the URI" -- do I need to prefix my import statement (I've tried a few combinations, but none worked)?

    import "nga_demo/Colors.qml" // runtime error: no such directory
    import "qrc:/nga_demo/Colors.qml" // same error as above
    import "qrc:/qt/qml/nga_demo/Colors.qml" // same error as above
    

    Thanks for any clarification.

    JKSHJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @JKSH said in issues with using qt_policy(SET QTP0001 NEW):

      You must import the URI as specified in the qt_add_qml_module() function that contains Colors.qml

      My function reads as:

      qt_add_qml_module(appnga_demo
          URI nga_demo
          VERSION 1.0
          QML_FILES
          (other files)
          Colors.qml
          (other files)
      

      I don't know what you mean by "import the URI" -- do I need to prefix my import statement (I've tried a few combinations, but none worked)?

      import "nga_demo/Colors.qml" // runtime error: no such directory
      import "qrc:/nga_demo/Colors.qml" // same error as above
      import "qrc:/qt/qml/nga_demo/Colors.qml" // same error as above
      

      Thanks for any clarification.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #10

      @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

      I don't know what you mean by "import the URI"

      qt_add_qml_module(appnga_demo
          URI nga_demo              # <-- This is your URI
      

      So, you do import nga_demo

      import "nga_demo/Colors.qml" // runtime error: no such directory
      import "qrc:/nga_demo/Colors.qml" // same error as above
      import "qrc:/qt/qml/nga_demo/Colors.qml" // same error as above
      

      We import QML modules; we don't import individual QML files (I can see why this is confusing, since you imported a *.js file)

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

      mzimmersM 1 Reply Last reply
      1
      • JKSHJ JKSH

        @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

        I don't know what you mean by "import the URI"

        qt_add_qml_module(appnga_demo
            URI nga_demo              # <-- This is your URI
        

        So, you do import nga_demo

        import "nga_demo/Colors.qml" // runtime error: no such directory
        import "qrc:/nga_demo/Colors.qml" // same error as above
        import "qrc:/qt/qml/nga_demo/Colors.qml" // same error as above
        

        We import QML modules; we don't import individual QML files (I can see why this is confusing, since you imported a *.js file)

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #11

        @JKSH oh, I see...I think I'm starting to see the value in this approach.

        So, I replaced all my import references from Color to nga_demo, which got rid of those runtime errors. Now, how do I go about referencing the properties defined in Colors.qml? Lines like this:

            property color textColor: checked ? Colors.primaryPurple : Colors.primaryText
        

        Don't work any more. Is Colors still a module, or is it now part of a larger module nga_demo?

        Thanks...

        JKSHJ 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @JKSH oh, I see...I think I'm starting to see the value in this approach.

          So, I replaced all my import references from Color to nga_demo, which got rid of those runtime errors. Now, how do I go about referencing the properties defined in Colors.qml? Lines like this:

              property color textColor: checked ? Colors.primaryPurple : Colors.primaryText
          

          Don't work any more. Is Colors still a module, or is it now part of a larger module nga_demo?

          Thanks...

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #12

          @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

          @JKSH oh, I see...I think I'm starting to see the value in this approach.

          So, I replaced all my import references from Color to nga_demo, which got rid of those runtime errors.

          Great!

          Now, how do I go about referencing the properties defined in Colors.qml? Lines like this:

              property color textColor: checked ? Colors.primaryPurple : Colors.primaryText
          

          Don't work any more. Is Colors still a module, or is it now part of a larger module nga_demo?

          It should work. Colors is not a module, it is a QML class/singleton inside the nga_demo module.

          What is the error message?

          Is set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) written before qt_add_qml_module()?

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

          mzimmersM JKSHJ 2 Replies Last reply
          0
          • JKSHJ JKSH

            @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

            @JKSH oh, I see...I think I'm starting to see the value in this approach.

            So, I replaced all my import references from Color to nga_demo, which got rid of those runtime errors.

            Great!

            Now, how do I go about referencing the properties defined in Colors.qml? Lines like this:

                property color textColor: checked ? Colors.primaryPurple : Colors.primaryText
            

            Don't work any more. Is Colors still a module, or is it now part of a larger module nga_demo?

            It should work. Colors is not a module, it is a QML class/singleton inside the nga_demo module.

            What is the error message?

            Is set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) written before qt_add_qml_module()?

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #13

            @JKSH currently the set_source_files_properties() call is just after the qt_add_qml_module(), but in a small test project I tried it both ways with the same (bad) results.

            Just to sanity check, I am no longer using my qml.qrc file, as my CMakeLists.txt file contains:

            set(CMAKE_AUTOMOC ON)
            set(CMAKE_AUTORCC ON)
            

            This is OK, right?

            Thanks...

            1 Reply Last reply
            0
            • JKSHJ JKSH

              @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

              @JKSH oh, I see...I think I'm starting to see the value in this approach.

              So, I replaced all my import references from Color to nga_demo, which got rid of those runtime errors.

              Great!

              Now, how do I go about referencing the properties defined in Colors.qml? Lines like this:

                  property color textColor: checked ? Colors.primaryPurple : Colors.primaryText
              

              Don't work any more. Is Colors still a module, or is it now part of a larger module nga_demo?

              It should work. Colors is not a module, it is a QML class/singleton inside the nga_demo module.

              What is the error message?

              Is set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE) written before qt_add_qml_module()?

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #14

              @JKSH said in issues with using qt_policy(SET QTP0001 NEW):

              What is the error message?

              Please share the message

              @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

              in a small test project

              Please share your small test project

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

              mzimmersM 1 Reply Last reply
              0
              • JKSHJ JKSH

                @JKSH said in issues with using qt_policy(SET QTP0001 NEW):

                What is the error message?

                Please share the message

                @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

                in a small test project

                Please share your small test project

                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #15

                @JKSH error message is: Unable to assign [undefined] to QColor.

                CMakeLists.txt (mostly boilerplate from Creator):

                cmake_minimum_required(VERSION 3.16)
                
                project(newqml VERSION 0.1 LANGUAGES CXX)
                
                set(CMAKE_CXX_STANDARD_REQUIRED ON)
                
                find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
                
                qt_standard_project_setup(REQUIRES 6.5)
                
                qt_add_executable(appnewqml
                    main.cpp
                )
                qt_add_qml_module(appnewqml
                    URI newqml
                    VERSION 1.0
                    QML_FILES
                        Main.qml
                        Colors.qml
                )
                set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
                
                set_target_properties(appnewqml PROPERTIES
                    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
                    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                    MACOSX_BUNDLE TRUE
                    WIN32_EXECUTABLE TRUE
                )
                
                target_link_libraries(appnewqml
                    PRIVATE Qt6::Quick
                )
                
                install(TARGETS appnewqml
                    BUNDLE DESTINATION .
                    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
                

                main.cpp:

                #include <QGuiApplication>
                #include <QQmlApplicationEngine>
                
                
                int main(int argc, char *argv[])
                {
                    QGuiApplication app(argc, argv);
                
                    QQmlApplicationEngine engine;
                    QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
                        &app, []() { QCoreApplication::exit(-1); },
                        Qt::QueuedConnection);
                    engine.loadFromModule("newqml", "Main");
                
                    return app.exec();
                }
                

                Main.qml:

                import QtQuick
                import QtQuick.Window
                import newqml
                
                Window {
                    width: 640
                    height: 480
                    visible: true
                    title: qsTr("Hello World")
                    color: Colors.cards
                }
                

                Thanks for looking at this.

                JKSHJ 1 Reply Last reply
                0
                • mzimmersM mzimmers

                  @JKSH error message is: Unable to assign [undefined] to QColor.

                  CMakeLists.txt (mostly boilerplate from Creator):

                  cmake_minimum_required(VERSION 3.16)
                  
                  project(newqml VERSION 0.1 LANGUAGES CXX)
                  
                  set(CMAKE_CXX_STANDARD_REQUIRED ON)
                  
                  find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
                  
                  qt_standard_project_setup(REQUIRES 6.5)
                  
                  qt_add_executable(appnewqml
                      main.cpp
                  )
                  qt_add_qml_module(appnewqml
                      URI newqml
                      VERSION 1.0
                      QML_FILES
                          Main.qml
                          Colors.qml
                  )
                  set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
                  
                  set_target_properties(appnewqml PROPERTIES
                      MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
                      MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                      MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                      MACOSX_BUNDLE TRUE
                      WIN32_EXECUTABLE TRUE
                  )
                  
                  target_link_libraries(appnewqml
                      PRIVATE Qt6::Quick
                  )
                  
                  install(TARGETS appnewqml
                      BUNDLE DESTINATION .
                      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
                  

                  main.cpp:

                  #include <QGuiApplication>
                  #include <QQmlApplicationEngine>
                  
                  
                  int main(int argc, char *argv[])
                  {
                      QGuiApplication app(argc, argv);
                  
                      QQmlApplicationEngine engine;
                      QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
                          &app, []() { QCoreApplication::exit(-1); },
                          Qt::QueuedConnection);
                      engine.loadFromModule("newqml", "Main");
                  
                      return app.exec();
                  }
                  

                  Main.qml:

                  import QtQuick
                  import QtQuick.Window
                  import newqml
                  
                  Window {
                      width: 640
                      height: 480
                      visible: true
                      title: qsTr("Hello World")
                      color: Colors.cards
                  }
                  

                  Thanks for looking at this.

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by JKSH
                  #16

                  @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

                  qt_add_qml_module(appnewqml
                      URI newqml
                      VERSION 1.0
                      QML_FILES
                          Main.qml
                          Colors.qml
                  )
                  set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
                  
                  1. It should be "Colors.qml", not "Color.qml"
                  2. Put set_source_files_properties(...) before qt_add_qml_module()

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

                  mzimmersM 1 Reply Last reply
                  1
                  • JKSHJ JKSH

                    @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

                    qt_add_qml_module(appnewqml
                        URI newqml
                        VERSION 1.0
                        QML_FILES
                            Main.qml
                            Colors.qml
                    )
                    set_source_files_properties(Color.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
                    
                    1. It should be "Colors.qml", not "Color.qml"
                    2. Put set_source_files_properties(...) before qt_add_qml_module()
                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by mzimmers
                    #17

                    @JKSH oops.

                    OK, definitely making progress here. It works in my minimal program, and I'm no longer getting the "undefined" error in my real program.

                    Several of my qml files are in a subdirectory "custom," which has its own CMakeFiles.txt file:

                    cmake_minimum_required(VERSION 3.16)
                    project(custom)
                    qt_add_qml_module(custom
                        URI custom
                        VERSION 1.0
                        QML_FILES
                        Roundbutton_custom.qml
                        Scrollbar_custom.qml
                        Switch_custom.qml
                        Tabbutton.qml
                        STATIC
                    )
                    

                    My main CMakeLists.txt file has an entry:

                    add_subdirectory(custom)
                    

                    and this all worked fine before I started switching over to 6.5. Do I need to do something extra for the files in this subdirectory? There's nothing special about them (no singletons, etc.)...they're just regular qml files.

                    Thanks...

                    EDIT:

                    I realize this no longer pertains to the original question in this topic; would it be better if I opened a new topic for this?

                    JKSHJ 1 Reply Last reply
                    0
                    • mzimmersM mzimmers

                      @JKSH oops.

                      OK, definitely making progress here. It works in my minimal program, and I'm no longer getting the "undefined" error in my real program.

                      Several of my qml files are in a subdirectory "custom," which has its own CMakeFiles.txt file:

                      cmake_minimum_required(VERSION 3.16)
                      project(custom)
                      qt_add_qml_module(custom
                          URI custom
                          VERSION 1.0
                          QML_FILES
                          Roundbutton_custom.qml
                          Scrollbar_custom.qml
                          Switch_custom.qml
                          Tabbutton.qml
                          STATIC
                      )
                      

                      My main CMakeLists.txt file has an entry:

                      add_subdirectory(custom)
                      

                      and this all worked fine before I started switching over to 6.5. Do I need to do something extra for the files in this subdirectory? There's nothing special about them (no singletons, etc.)...they're just regular qml files.

                      Thanks...

                      EDIT:

                      I realize this no longer pertains to the original question in this topic; would it be better if I opened a new topic for this?

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #18

                      @mzimmers said in issues with using qt_policy(SET QTP0001 NEW):

                      OK, definitely making progress here. It works in my minimal program, and I'm no longer getting the "undefined" error in my real program.

                      Congrats!

                      Several of my qml files are in a subdirectory "custom," which has its own CMakeFiles.txt file

                      Notice that this is a different QML module with a different URI.

                      • main.qml needs to do import custom to use Tabbutton
                      • Tabbutton.qml needs to do import nga_demo to use Colors

                      realize this no longer pertains to the original question in this topic; would it be better if I opened a new topic for this?

                      Yes, best open new threads for new questions :)

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

                      1 Reply Last reply
                      0
                      • mzimmersM mzimmers has marked this topic as solved on

                      • Login

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