slint-ui/slint · error · AttributeError

Callback ' ' cannot be used with a callback decorator for…

Error message

Callback '${name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component

What it means

Raised by the @slint.callback decorator when decorating an async function with a callback name that does not exist in the compiled Slint component. callback_returns_void(name) returned None, meaning the component defines no callback with that name, so the decorator cannot wire the handler.

Solutions

  1. Verify the callback is declared in the .slint component with exactly this name and fix any spelling mismatch.
  2. Ensure you are decorating the correct class — a callback in an exported global must be handled with the global-aware decorator form.
  3. Rebuild/recompile the .slint file so the component definition includes the callback, then re-run.

Example fix

# before (.slint has: callback submit();) but Python says
@slint.callback("on_submit")
async def submit(): ...

# after: names must match the .slint declaration
@slint.callback("submit")
async def submit(): ...
Defensive patterns

Strategy: validation

Validate before calling

if comp.callback_returns_void(name) is None:
    raise NameError(f"callback '{name}' not declared in Slint component")

Try / catch

try:
    result = slint.load_file("app.slint")
except slint.CompileError:
    ...  # names mismatch usually surfaces at load/decoration time

Prevention

When it happens

Trigger: Using @slint.callback("name") on an async function where `name` is misspelled, was renamed in the .slint file, or is defined in a global/component other than the decorated class.

Common situations: Typos between Python and .slint; refactoring callback names in the UI file without updating Python handlers; expecting the decorator to auto-create the callback (it only binds existing ones); attaching to an instance callback from the wrong component class.

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


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

Appendix: source

Thrown at api/python/slint/slint/__init__.py:188

                is_async = getattr(value, "slint.async", False)
                if is_async:
                    if "global_name" in callback_info:
                        global_name = callback_info["global_name"]
                        is_void = compdef.global_callback_returns_void(
                            global_name, name
                        )
                        if is_void is None:
                            raise AttributeError(
                                f"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component"
                            )
                        if not is_void:
                            raise RuntimeError(
                                f"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it doesn't return void"
                            )
                    else:
                        is_void = compdef.callback_returns_void(name)
                        if is_void is None:
                            raise AttributeError(
                                f"Callback '{name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component"
                            )
                        if not is_void:
                            raise RuntimeError(
                                f"Callback '{name}' cannot be used with a callback decorator for an async function, as it doesn't return void"
                            )

                def mk_callback(
                    self: Any, callback: typing.Callable[..., Any]
                ) -> typing.Callable[..., Any]:
                    def invoke(*args: Any, **kwargs: Any) -> Any:
                        return callback(self, *args, **kwargs)

                    return invoke

                if "global_name" in callback_info:
                    self.__instance__.set_global_callback(
                        callback_info["global_name"], name, mk_callback(self, value)

View on GitHub (pinned to bb937076de)