slint-ui/slint · error

Cannot invoke callback

Error message

Cannot invoke callback {name}: {e}

What it means

LiveComponent.invoke forwards a named callback invocation to the compiled component instance and panics on error. This fires at runtime in the live-preview tool when invoking a callback fails — most often the callback name doesn't exist on the component (typo or stale property panel state), the argument Values don't match the callback signature, or the callback itself errored. It's a fail-fast guard for tooling, replacing a silent swallowed error.

Solutions

  1. Verify the callback is declared on the top-level component with a matching signature.
  2. Check argument count and types against the callback declaration.
  3. Use the raw instance invoke (Result-returning) if you need graceful failure handling.
  4. Re-load the component after edits and refresh the list of callable callbacks.

Example fix

// before
live.invoke("on_clicked", &[]); // not a declared callback
// after
live.invoke("clicked", &[]); // match declared callback clicked();
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the callback exists and arity matches before invoking
// if instance.definition().callbacks(name).iter().any(|c| c.name == cb && c.args.len() == n) { ... }

Try / catch

match instance.invoke(name, args) {
    Ok(v) => v,
    Err(e) => { eprintln!("invoke {name} failed: {e}"); Value::default() }
}

Prevention

When it happens

Trigger: Calling LiveComponent::invoke with a callback name not declared on the component, wrong number of arguments, or argument types not matching the callback signature.

Common situations: Automated tests/tooling invoking callbacks after the .slint file was edited; invoking a handler that only exists on a sub-element; passing a string where the callback expects an int.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

    pub fn set_property(&self, name: &str, value: Value) {
        self.properties.borrow_mut().insert(name.into(), value.clone());
        self.instance()
            .set_property(name, value)
            .unwrap_or_else(|e| panic!("Cannot set property {name}: {e}"))
    }

    /// Forward to get_property
    pub fn get_property(&self, name: &str) -> Value {
        self.instance()
            .get_property(name)
            .unwrap_or_else(|e| panic!("Cannot get property {name}: {e}"))
    }

    /// Forward to invoke
    pub fn invoke(&self, name: &str, args: &[Value]) -> Value {
        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}"))
    }

View on GitHub (pinned to 3a7e700487)