slint-ui/slint · error

slint_testing_use_native_popup called without testing…

Error message

slint_testing_use_native_popup called without testing backend/adapter

What it means

The testing backend's FFI helper `slint_testing_use_native_popup` downcasts the given `WindowAdapterRc` to the `TestingWindow` adapter and panics if the downcast fails. This means the popup native-flag test API was invoked on a window that is not backed by the Slint testing backend (e.g. the winit or Qt backend is active instead).

Solutions

  1. Initialize the testing backend before any window is created: call `slint_testing::init()` (or `init_no_event_loop()` / `init_integration_test_*`) at test start.
  2. Ensure only the testing backend feature is enabled in the test build so the platform adapter is TestingWindow.
  3. Verify the window adapter you pass is the one created after testing-backend init, not one captured earlier from a real backend.

Example fix

// before
#[test]
fn popup_test() {
    // no testing backend init -> panics
    slint_testing_use_native_popup(&adapter, true);
}

// after
#[test]
fn popup_test() {
    slint_testing::init_no_event_loop(); // installs TestingWindow adapter
    slint_testing_use_native_popup(&adapter, true);
}
Defensive patterns

Strategy: validation

Validate before calling

// before calling popup test helpers, ensure testing backend is active
fn testing_backend_active() -> bool {
    std::env::var("SLINT_BACKEND").map(|b| b.is_empty() || b == "testing").unwrap_or(true)
    // plus: init was called first — enforce via Once in your test harness
}

Prevention

When it happens

Trigger: Calling the internal FFI `slint_testing_use_native_popup` (used by Slint test infrastructure to force native popups) when the process's window adapter is the platform's real backend adapter rather than `crate::testing_backend::TestingWindow`.

Common situations: Running Slint tests without first initializing the testing backend (missing `slint_testing::init()` or `init_no_event_loop()`); a test binary that links the real backend (winit/qt) via feature selection; calling the helper after the platform was initialized with a different adapter.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at internal/backends/testing/ffi.rs:82

}

#[unsafe(no_mangle)]
pub extern "C" fn slint_send_keyboard_string_sequence(
    sequence: &SharedString,
    window_adapter: &WindowAdapterRc,
) {
    crate::testing_backend::send_keyboard_string_sequence(sequence, window_adapter);
}

#[unsafe(no_mangle)]
pub extern "C" fn slint_testing_use_native_popup(window_adapter: &WindowAdapterRc, native: bool) {
    window_adapter
        .internal(i_slint_core::InternalToken)
        .and_then(|wa| {
            (wa as &dyn core::any::Any).downcast_ref::<crate::testing_backend::TestingWindow>()
        })
        .map(|testing_window| testing_window.use_native_popup(native))
        .expect("slint_testing_use_native_popup called without testing backend/adapter");
}

#[unsafe(no_mangle)]
pub extern "C" fn slint_testing_active_popup_count(window_adapter: &WindowAdapterRc) -> usize {
    WindowInner::from_pub(window_adapter.window()).active_popups().len()
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn slint_testing_element_visit_elements(
    root: &ItemTreeRc,
    user_data: *mut c_void,
    visitor: unsafe extern "C" fn(*mut c_void, &ElementHandle) -> bool,
) -> bool {
    RootWrapper(root)
        .root_element()
        .query_descendants()
        .match_predicate(move |element| unsafe { visitor(user_data, element) })
        .find_first()

View on GitHub (pinned to bb937076de)