slint-ui/slint · error · AttributeError
Callback '{name}' in global '{global_name}' cannot be used w
Error message
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 What it means
When a Python class subclasses a generated Slint component and decorates an `async def` method with @slint.callback (with a global_name in the callback info), Slint validates at instantiation time that the global actually declares that callback: compdef.global_callback_returns_void(global_name, name) returns None when the callback does not exist in the Slint global, which raises this AttributeError. It fires from cls_init, i.e. the moment you construct the subclass.
Source
Thrown at api/python/slint/slint/__init__.py:178
def _build_class(
compdef: native.ComponentDefinition,
) -> typing.Callable[..., Component]:
def cls_init(self: Component, **kwargs: Any) -> Any:
self.__instance__ = compdef.create()
for name, value in self.__class__.__dict__.items():
if hasattr(value, "slint.callback"):
callback_info = getattr(value, "slint.callback")
name = callback_info["name"]
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(View on GitHub (pinned to a9ea814a58)
Solutions
- Declare the callback inside the global in the .slint file: `export global Foo { callback clicked(); }`.
- Make the Python method name match the Slint callback name exactly (use underscores where .slint uses dashes).
- Re-run slint.load_file()/load_str() with the updated .slint before instantiating the subclass.
- If the method is not meant to be invoked from Slint, remove the @slint.callback decorator from it.
Example fix
# before (main.slint)
export global Actions { callback submit(string); }
# app.py — no `quit` callback exists in the global
@slint.callback
async def quit(self): ...
# after — declare it first
export global Actions {
callback submit(string);
callback quit();
} Defensive patterns
Strategy: validation
Validate before calling
# Before instantiating, assert every @slint.callback async method exists in the loaded globals
class App(slint.Component):
@slint.callback
async def quit(self): ...
names = {n.replace("-", "_") for n in dir(App)} # extend with your globals' callbacks
declared = {c.replace("-", "_") for g in app_globals for c in compdef.global_callbacks(g)}
missing = names - declared
if missing: raise SystemExit(f"Callbacks not declared in .slint: {missing}") Try / catch
try:
app = App()
except AttributeError as e:
raise SystemExit(f"@slint.callback name mismatch: {e} — declare the callback in the global and keep names in sync") from e Prevention
- Declare the callback in the global before writing the Python handler.
- Keep one source of truth for names; regenerate/reload after .slint edits (re-run slint.load_file).
- Remember dashes in Slint names map to underscores in Python.
When it happens
Trigger: `@slint.callback` on an `async def` method of a global shim class where the method name does not match any `callback` declared inside the corresponding `export global { ... }` in the .slint file (typos, renamed callback, dashes vs underscores mismatch, or a helper method decorated by mistake).
Common situations: The callback was renamed in .slint but not in Python (or vice versa); the .slint file was edited but slint.load_file was not re-run; the developer decorated a plain helper method with @slint.callback; forgetting that Slint names with dashes map to Python underscores.
Related errors
- Callback '{name}' in global '{global_name}' cannot be used w
- Callback '{name}' cannot be used with a callback decorator f
- Callback '{name}' cannot be used with a callback decorator f
- Could not compile {path}
- run_until_complete's future isn't done
AI-assisted analysis of slint-ui/slint@a9ea814a58 (2026-08-16).
Data as JSON: /api/errors/a45df397836f9020.
Report an issue: GitHub.