issues with using qt_policy(SET QTP0001 NEW)
-
@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
@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.
-
@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.
@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)
-
@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)
@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...
-
@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...
@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 thenga_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()? -
@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 thenga_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()?@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...
-
@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 thenga_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()?@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
-
@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
@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.
-
@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.
@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)
- It should be "Colors.qml", not "Color.qml"
- Put
set_source_files_properties(...)
before qt_add_qml_module()
-
@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)
- It should be "Colors.qml", not "Color.qml"
- Put
set_source_files_properties(...)
before qt_add_qml_module()
@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?
-
@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?
@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 :)
- main.qml needs to do
-
M mzimmers has marked this topic as solved on