slint-ui/slint · error
Cannot set property
Error message
Cannot set property {global_name}::{name}: {e} What it means
LiveComponent::set_global_property panics when the interpreter cannot set the property on the named global singleton. The value is first cached for hot-reload replay; if the interpreter returns an Err (unknown global, unknown property, or type mismatch), the code panics because a failed property set would leave the live preview inconsistent.
Solutions
- Ensure the global is exported (`export global Foo { ... }`) in the compiled .slint
- Check the property exists on that global and the Value type matches the declared property type
- Pass global and property as two separate arguments, not a combined dotted string
Example fix
// before
live.set_global_property("Styles", "primairy-color", Value::String("red".into())); // typo + wrong type
// after
live.set_global_property("Styles", "primary-color", Value::Color(Color::from_rgb_u8(255,0,0))); Defensive patterns
Strategy: validation
Validate before calling
fn global_prop_ok(instance: &slint_interpreter::ComponentInstance, g: &str, p: &str, v: &Value) -> bool {
instance.definition().globals().iter().any(|g2| g2.name == g)
&& instance.definition().root_component()
.properties().iter()
.any(|prop| prop.name == p && prop.ty == v.value_type())
} Try / catch
// panic! is not catchable; validate global/property/type first
if value.value_type() == expected_type {
live.set_global_property("Styles", "primary-color", value);
} Prevention
- Keep a typed wrapper per global property instead of raw (name, Value) calls
- Export globals explicitly and test global names after each .slint edit
- Coerce values with Value::from on the declared Rust type before setting
When it happens
Trigger: set_global_property with a global_name that is not an exported global, a property name not declared in that global, or a Value whose type does not match the declared property type.
Common situations: Using `{global}.{prop}` or `{global}::{prop}` style strings instead of separate arguments; global not exported from the .slint file; passing a string where the property is an int/color; stale globals after hot reload.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Cannot get property
- Cannot invoke callback
- Cannot set callback
- Global was just valid
- root_component() called on a definition built without…
AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16).
Data as JSON: /api/errors/8eea20ee8b44edfa.
Report an issue: GitHub.
Appendix: source
Thrown at internal/live-preview/live_component.rs:217
self.instance()
.invoke(name, args)
.unwrap_or_else(|e| panic!("Cannot invoke callback {name}: {e}"))
}
/// Forward to set_callback
pub fn set_callback(&self, name: &str, callback: Rc<dyn Fn(&[Value]) -> Value + 'static>) {
self.callbacks.borrow_mut().insert(name.into(), callback.clone());
self.instance()
.set_callback(name, move |args| callback(args))
.unwrap_or_else(|e| panic!("Cannot set callback {name}: {e}"));
}
/// forward to set_global_property
pub fn set_global_property(&self, global_name: &str, name: &str, value: Value) {
self.properties.borrow_mut().insert(format!("{global_name}.{name}"), value.clone());
self.instance()
.set_global_property(global_name, name, value)
.unwrap_or_else(|e| panic!("Cannot set property {global_name}::{name}: {e}"))
}
/// forward to get_global_property
pub fn get_global_property(&self, global_name: &str, name: &str) -> Value {
self.instance()
.get_global_property(global_name, name)
.unwrap_or_else(|e| panic!("Cannot get property {global_name}::{name}: {e}"))
}
/// Forward to invoke_global
pub fn invoke_global(&self, global_name: &str, name: &str, args: &[Value]) -> Value {
self.instance()
.invoke_global(global_name, name, args)
.unwrap_or_else(|e| panic!("Cannot invoke callback {global_name}::{name}: {e}"))
}
/// Forward to set_global_callback
pub fn set_global_callback(View on GitHub (pinned to 3a7e700487)