-
Is there an example of how to test cxx-qt code that requires a QCoreApplication? I've wrapped QJSEngine/QJSValue/etc. and I'm trying to write serialization/deserialization tests but I'm having problems with QCoreApplication engine with the following errors (after restricting the number of threads to 1 so its all on the main thread):
This is the test code I'm trying to use: fn init() -> UniquePtr<QQmlApplicationEngine> {
QQmlApplicationEngine::new()
}
/// Setup function to create a QJSEngine and evaluate a script
fn setup_and_evaluate(script: &str) -> (UniquePtr<QJSEngine>, UniquePtr<QJSValue>) {
let mut engine_ptr = QJSEngine::new();
let engine = engine_ptr.as_mut().unwrap();
let value = engine.evaluate(&QString::from(script), &QString::from(""), 1);
(engine_ptr, value)
}
#[test]
fn test_deserialize_bool() {
let _ = init();
let (mut engine, value) = setup_and_evaluate("true");
let deserialized: bool = engine.as_mut().unwrap().deserialize(&value).unwrap();
assert_eq!(deserialized, true);
} I believe in C++ there's macros like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I was instantiating |
Beta Was this translation helpful? Give feedback.
I was instantiating
QQmlApplicationEngine
instead ofQCoreApplication
🤦