slint-ui/slint · error

Cannot set property

Error message

Cannot set property {name}: {e}

What it means

Panic in live-preview's reload_properties_and_callbacks when set_global_property fails after a hot reload. The stored (name, value) pair could not be re-applied to the freshly reloaded component instance.

Solutions

  1. Re-declare the global property with the same name and type as before the reload, or clear the stale stored value.
  2. Check the error detail {e} for the exact missing/mismatched property name and fix the .slint source.
  3. Restart the live preview session to drop stale property state.
  4. Keep global property names and types stable across incremental edits.

Example fix

// before (global renamed in .slint)
export global Settings { property<int> theme; }
// after: keep the old name or update the previewer state
export global Settings { property<int> color-scheme; } // update all set_global_property("Settings", "theme") call sites to "color-scheme"
Defensive patterns

Strategy: fallback

Validate before calling

// Before re-applying after reload, verify the global property still exists
// if instance.definition().globals().contains(global) && exists prop { set_global_property(...) }

Try / catch

// Use the raw instance API for graceful handling
if let Err(e) = instance.set_global_property(global, prop, value) {
    eprintln!("skipping stale global {global}.{prop}: {e}");
}

Prevention

When it happens

Trigger: Live-preview reload where a previously set global property (name contains a '.') no longer exists or its type changed in the reloaded .slint source.

Common situations: Editing a .slint file during development: renaming a global, changing a global property's type, deleting a global, or changing the property's type from string to int while live preview keeps old values.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of slint-ui/slint@3a7e700487 (2026-09-16). Data as JSON: /api/errors/ccca912c0ea85598. Report an issue: GitHub.

Appendix: source

Thrown at internal/live-preview/live_component.rs:140

            unreachable!("Compiler returned Pending")
        };
        Watcher::update_watched_paths(
            &self.watcher,
            std::iter::once(self.file_name.clone())
                .chain(result.watch_paths(i_slint_core::InternalToken).iter().cloned())
                .chain(self.extra_watch_paths.iter().cloned()),
        );
        result
    }

    /// Reload the properties and callbacks after a reload()
    pub fn reload_properties_and_callbacks(&self) {
        // Set the properties
        for (name, value) in self.properties.borrow_mut().iter() {
            if let Some((global, prop)) = name.split_once('.') {
                self.instance()
                    .set_global_property(global, prop, value.clone())
                    .unwrap_or_else(|e| panic!("Cannot set property {name}: {e}"));
            } else {
                self.instance()
                    .set_property(name, value.clone())
                    .unwrap_or_else(|e| panic!("Cannot set property {name}: {e}"));
            }
        }
        for (name, callback) in self.callbacks.borrow_mut().iter() {
            let callback = callback.clone();
            if let Some((global, prop)) = name.split_once('.') {
                self.instance()
                    .set_global_callback(global, prop, move |args| callback(args))
                    .unwrap_or_else(|e| panic!("Cannot set callback {name}: {e}"));
            } else {
                self.instance()
                    .set_callback(name, move |args| callback(args))
                    .unwrap_or_else(|e| panic!("Cannot set callback {name}: {e}"));
            }
        }

View on GitHub (pinned to 3a7e700487)