Skip to content

Commit aedcc68

Browse files
ahayzen-kdabBe-ing
authored andcommitted
examples: add qml_uncreatable test
1 parent 06fc679 commit aedcc68

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

examples/qml_features/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ copy_qml_test(signals)
8383
copy_qml_test(singleton)
8484
copy_qml_test(threading)
8585
copy_qml_test(types)
86+
copy_qml_test(uncreatable)
8687

8788
add_executable(${APP_NAME}_test
8889
cpp/qabstractlistmodelcxx.h

examples/qml_features/rust/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() {
2020
.file("src/properties.rs")
2121
.file("src/threading.rs")
2222
.file("src/types.rs")
23+
.file("src/uncreatable.rs")
2324
// custom_object.cpp/h need to be handled here rather than CMakeLists.txt,
2425
// otherwise linking cargo tests fails because the symbols from those files are not found.
2526
.cc_builder(|cc| {

examples/qml_features/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ mod signals;
1515
mod singleton;
1616
mod threading;
1717
mod types;
18+
mod uncreatable;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
// ANCHOR: book_macro_code
7+
#[cxx_qt::bridge(cxx_file_stem = "rust_uncreatable")]
8+
pub mod ffi {
9+
#[cxx_qt::qobject(qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0", qml_uncreatable)]
10+
#[derive(Default)]
11+
pub struct RustUncreatable {
12+
#[qproperty]
13+
value: i32,
14+
}
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
import QtQuick 2.12
6+
import QtTest 1.12
7+
8+
TestCase {
9+
id: root
10+
name: "UncreatableTests"
11+
12+
function test_uncreatable() {
13+
try {
14+
const obj = Qt.createQmlObject(`
15+
import com.kdab.cxx_qt.demo 1.0
16+
17+
RustUncreatable {
18+
19+
}
20+
`,
21+
root,
22+
"uncreatableObject"
23+
);
24+
fail("Uncreatable type should not be creatable");
25+
} catch (error) {
26+
verify(error.qmlErrors !== undefined);
27+
compare(error.qmlErrors.length, 1);
28+
// Check for Qt 5 or Qt 6 error message
29+
verify(error.qmlErrors[0].message === "Element is not creatable." || error.qmlErrors[0].message === "Type cannot be created in QML.");
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)