diff --git a/api/cpp/include/slint.h b/api/cpp/include/slint.h index 7e6794b4f..551fdb675 100644 --- a/api/cpp/include/slint.h +++ b/api/cpp/include/slint.h @@ -124,6 +124,11 @@ upgrade_item_weak(const cbindgen_private::ItemWeak &item_weak) } } +inline void debug(const SharedString &str) +{ + cbindgen_private::slint_debug(&str); +} + } // namespace private_api template diff --git a/api/cpp/lib.rs b/api/cpp/lib.rs index 4a87e0968..4c35154f0 100644 --- a/api/cpp/lib.rs +++ b/api/cpp/lib.rs @@ -152,6 +152,11 @@ pub extern "C" fn slint_string_to_float(string: &SharedString, value: &mut f32) } } +#[no_mangle] +pub extern "C" fn slint_debug(string: &SharedString) { + i_slint_core::debug_log!("{string}"); +} + #[cfg(not(feature = "std"))] mod allocator { use core::alloc::Layout; diff --git a/api/rs/slint/private_unstable_api.rs b/api/rs/slint/private_unstable_api.rs index f29305794..18bc6ed6a 100644 --- a/api/rs/slint/private_unstable_api.rs +++ b/api/rs/slint/private_unstable_api.rs @@ -127,12 +127,7 @@ pub fn debug(s: SharedString) { #[cfg(feature = "log")] log::debug!("{s}"); #[cfg(not(feature = "log"))] - { - #[cfg(all(feature = "std", not(target_arch = "wasm32")))] - println!("{s}"); - #[cfg(any(not(feature = "std"), target_arch = "wasm32"))] - i_slint_core::debug_log!("{s}"); - } + i_slint_core::debug_log!("{s}"); } pub fn ensure_backend() -> Result<(), crate::PlatformError> { diff --git a/internal/compiler/generator/cpp.rs b/internal/compiler/generator/cpp.rs index 2768a2125..ee13e1e34 100644 --- a/internal/compiler/generator/cpp.rs +++ b/internal/compiler/generator/cpp.rs @@ -3128,7 +3128,7 @@ fn compile_builtin_function_call( BuiltinFunction::AnimationTick => "slint::cbindgen_private::slint_animation_tick()".into(), BuiltinFunction::Debug => { ctx.generator_state.conditional_includes.iostream.set(true); - format!("std::cout << {} << std::endl;", a.join("<<")) + format!("slint::private_api::debug({});", a.join(",")) } BuiltinFunction::Mod => { ctx.generator_state.conditional_includes.cmath.set(true);