Package/namespace directive for components #4871
-
Currently, all C++ generated code will be declared within the global scope, so if you have something like... export component MainWindow inherits Window { ... } ...then the generated C++ header will introduce a global-scope type like... class MainWindow { ... }; Personally, I like to keep my code rather organized like... namespace project::core { ... }
namespace project::gui { ... }
namespace project::cli { ... } ...so having my auto-generated code be outside these namespaces makes it a bit awkward. I could do something like... namespace project::gui { using MainWindow = ::MainWindow; } ...to pretend it was part of my scope all along, but as a global variable there's always the risk of ODR violations One thought could be to have a package project::gui;
export component MainWindow inherits Window { ... } ...could lead to generated code like... namespace project::gui {
class MainWindow { ... };
} For languages like Python, this could be a little strange to implement, since namespacing is achieved through directory structure. I'm not as familiar with how it works in Rust and Typescript, but there could be some challenges there as well. Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Since Slint 1.5, it is possible to specify NAMESPACE in the cmake command to generate the classes in a namespace: Example: slint/examples/todo/cpp/CMakeLists.txt Line 13 in a1c2836 |
Beta Was this translation helpful? Give feedback.
Since Slint 1.5, it is possible to specify NAMESPACE in the cmake command to generate the classes in a namespace:
https://slint.dev/releases/1.5.0/docs/cpp/cmake_reference
Example:
slint/examples/todo/cpp/CMakeLists.txt
Line 13 in a1c2836