Skip to content

Commit 0b73735

Browse files
committed
cxx-qt-gen: use extern "C++" block to define Qt lib types
1 parent 617f420 commit 0b73735

30 files changed

+214
-321
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ mod my_object {
5858

5959
const DEFAULT_STR: &str = r#"{"number": 1, "string": "Hello World!"}"#;
6060

61+
#[namespace = ""]
62+
unsafe extern "C++" {
63+
include!("cxx-qt-lib/include/qt_types.h");
64+
type QString = cxx_qt_lib::QString;
65+
}
66+
6167
pub struct Data {
6268
pub number: i32,
6369
pub string: UniquePtr<QString>,

cxx-qt-gen/src/gen_rs.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -533,33 +533,6 @@ pub fn generate_qobject_cxx(
533533
#[cxx_name = #class_name_str]
534534
type #rust_class_name_cpp;
535535

536-
include!("cxx-qt-lib/include/qt_types.h");
537-
#[namespace = ""]
538-
type QColor = cxx_qt_lib::QColor;
539-
#[namespace = ""]
540-
type QDate = cxx_qt_lib::QDate;
541-
#[namespace = ""]
542-
type QDateTime = cxx_qt_lib::QDateTime;
543-
#[namespace = ""]
544-
type QPoint = cxx_qt_lib::QPoint;
545-
#[namespace = ""]
546-
type QPointF = cxx_qt_lib::QPointF;
547-
#[namespace = ""]
548-
type QRect = cxx_qt_lib::QRect;
549-
#[namespace = ""]
550-
type QRectF = cxx_qt_lib::QRectF;
551-
#[namespace = ""]
552-
type QSize = cxx_qt_lib::QSize;
553-
#[namespace = ""]
554-
type QSizeF = cxx_qt_lib::QSizeF;
555-
#[namespace = ""]
556-
type QString = cxx_qt_lib::QString;
557-
#[namespace = ""]
558-
type QTime = cxx_qt_lib::QTime;
559-
#[namespace = ""]
560-
type QUrl = cxx_qt_lib::QUrl;
561-
#[namespace = ""]
562-
type QVariant = cxx_qt_lib::QVariant;
563536
#update_requester_type
564537

565538
#(#cpp_functions)*

cxx-qt-gen/test_inputs/handlers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
mod my_object {
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QString = cxx_qt_lib::QString;
6+
}
7+
28
#[derive(Default)]
39
pub struct Data {
410
number: i32,

cxx-qt-gen/test_inputs/invokables.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
mod my_object {
2-
use cxx_qt_lib::QColor;
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QColor = cxx_qt_lib::QColor;
6+
type QPoint = cxx_qt_lib::QPoint;
7+
type QString = cxx_qt_lib::QString;
8+
}
39

410
#[derive(Default)]
511
pub struct RustObj;

cxx-qt-gen/test_inputs/properties.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
mod my_object {
2-
use cxx_qt_lib::QColor;
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QColor = cxx_qt_lib::QColor;
6+
}
37

48
#[derive(Default)]
59
pub struct Data {

cxx-qt-gen/test_inputs/signals.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
mod my_object {
2-
use cxx_qt_lib::QVariant;
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QPoint = cxx_qt_lib::QPoint;
6+
type QVariant = cxx_qt_lib::QVariant;
7+
}
38

49
#[cxx_qt::signals(MyObject)]
510
enum MySignals {

cxx-qt-gen/test_inputs/types_qt_invokable.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
mod my_object {
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QColor = cxx_qt_lib::QColor;
6+
type QDate = cxx_qt_lib::QDate;
7+
type QDateTime = cxx_qt_lib::QDateTime;
8+
type QPoint = cxx_qt_lib::QPoint;
9+
type QPointF = cxx_qt_lib::QPointF;
10+
type QRect = cxx_qt_lib::QRect;
11+
type QRectF = cxx_qt_lib::QRectF;
12+
type QSize = cxx_qt_lib::QSize;
13+
type QSizeF = cxx_qt_lib::QSizeF;
14+
type QString = cxx_qt_lib::QString;
15+
type QTime = cxx_qt_lib::QTime;
16+
type QUrl = cxx_qt_lib::QUrl;
17+
type QVariant = cxx_qt_lib::QVariant;
18+
}
19+
220
#[derive(Default)]
321
pub struct Data;
422

cxx-qt-gen/test_inputs/types_qt_property.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
mod my_object {
2+
#[namespace = ""]
3+
unsafe extern "C++" {
4+
include!("cxx-qt-lib/include/qt_types.h");
5+
type QColor = cxx_qt_lib::QColor;
6+
type QDate = cxx_qt_lib::QDate;
7+
type QDateTime = cxx_qt_lib::QDateTime;
8+
type QPoint = cxx_qt_lib::QPoint;
9+
type QPointF = cxx_qt_lib::QPointF;
10+
type QRect = cxx_qt_lib::QRect;
11+
type QRectF = cxx_qt_lib::QRectF;
12+
type QSize = cxx_qt_lib::QSize;
13+
type QSizeF = cxx_qt_lib::QSizeF;
14+
type QString = cxx_qt_lib::QString;
15+
type QTime = cxx_qt_lib::QTime;
16+
type QUrl = cxx_qt_lib::QUrl;
17+
type QVariant = cxx_qt_lib::QVariant;
18+
}
19+
220
#[derive(Default)]
321
pub struct Data {
422
color: UniquePtr<QColor>,

cxx-qt-gen/test_outputs/custom_default.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ mod my_object {
66
#[cxx_name = "MyObject"]
77
type MyObjectQt;
88

9-
include!("cxx-qt-lib/include/qt_types.h");
10-
#[namespace = ""]
11-
type QColor = cxx_qt_lib::QColor;
12-
#[namespace = ""]
13-
type QDate = cxx_qt_lib::QDate;
14-
#[namespace = ""]
15-
type QDateTime = cxx_qt_lib::QDateTime;
16-
#[namespace = ""]
17-
type QPoint = cxx_qt_lib::QPoint;
18-
#[namespace = ""]
19-
type QPointF = cxx_qt_lib::QPointF;
20-
#[namespace = ""]
21-
type QRect = cxx_qt_lib::QRect;
22-
#[namespace = ""]
23-
type QRectF = cxx_qt_lib::QRectF;
24-
#[namespace = ""]
25-
type QSize = cxx_qt_lib::QSize;
26-
#[namespace = ""]
27-
type QSizeF = cxx_qt_lib::QSizeF;
28-
#[namespace = ""]
29-
type QString = cxx_qt_lib::QString;
30-
#[namespace = ""]
31-
type QTime = cxx_qt_lib::QTime;
32-
#[namespace = ""]
33-
type QUrl = cxx_qt_lib::QUrl;
34-
#[namespace = ""]
35-
type QVariant = cxx_qt_lib::QVariant;
36-
379
#[rust_name = "public"]
3810
fn getPublic(self: &MyObjectQt) -> i32;
3911
#[rust_name = "set_public"]

cxx-qt-gen/test_outputs/handlers.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ mod my_object {
66
#[cxx_name = "MyObject"]
77
type MyObjectQt;
88

9-
include!("cxx-qt-lib/include/qt_types.h");
10-
#[namespace = ""]
11-
type QColor = cxx_qt_lib::QColor;
12-
#[namespace = ""]
13-
type QDate = cxx_qt_lib::QDate;
14-
#[namespace = ""]
15-
type QDateTime = cxx_qt_lib::QDateTime;
16-
#[namespace = ""]
17-
type QPoint = cxx_qt_lib::QPoint;
18-
#[namespace = ""]
19-
type QPointF = cxx_qt_lib::QPointF;
20-
#[namespace = ""]
21-
type QRect = cxx_qt_lib::QRect;
22-
#[namespace = ""]
23-
type QRectF = cxx_qt_lib::QRectF;
24-
#[namespace = ""]
25-
type QSize = cxx_qt_lib::QSize;
26-
#[namespace = ""]
27-
type QSizeF = cxx_qt_lib::QSizeF;
28-
#[namespace = ""]
29-
type QString = cxx_qt_lib::QString;
30-
#[namespace = ""]
31-
type QTime = cxx_qt_lib::QTime;
32-
#[namespace = ""]
33-
type QUrl = cxx_qt_lib::QUrl;
34-
#[namespace = ""]
35-
type QVariant = cxx_qt_lib::QVariant;
36-
379
#[namespace = "rust::cxxqtlib1"]
3810
type UpdateRequester = cxx_qt_lib::UpdateRequesterCpp;
3911

@@ -67,6 +39,12 @@ mod my_object {
6739
#[cxx_name = "handleUpdateRequest"]
6840
fn call_handle_update_request(self: &mut RustObj, cpp: Pin<&mut MyObjectQt>);
6941
}
42+
43+
#[namespace = ""]
44+
unsafe extern "C++" {
45+
include!("cxx-qt-lib/include/qt_types.h");
46+
type QString = cxx_qt_lib::QString;
47+
}
7048
}
7149

7250
pub use self::cxx_qt_my_object::*;

cxx-qt-gen/test_outputs/invokables.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ mod my_object {
66
#[cxx_name = "MyObject"]
77
type MyObjectQt;
88

9-
include!("cxx-qt-lib/include/qt_types.h");
10-
#[namespace = ""]
11-
type QColor = cxx_qt_lib::QColor;
12-
#[namespace = ""]
13-
type QDate = cxx_qt_lib::QDate;
14-
#[namespace = ""]
15-
type QDateTime = cxx_qt_lib::QDateTime;
16-
#[namespace = ""]
17-
type QPoint = cxx_qt_lib::QPoint;
18-
#[namespace = ""]
19-
type QPointF = cxx_qt_lib::QPointF;
20-
#[namespace = ""]
21-
type QRect = cxx_qt_lib::QRect;
22-
#[namespace = ""]
23-
type QRectF = cxx_qt_lib::QRectF;
24-
#[namespace = ""]
25-
type QSize = cxx_qt_lib::QSize;
26-
#[namespace = ""]
27-
type QSizeF = cxx_qt_lib::QSizeF;
28-
#[namespace = ""]
29-
type QString = cxx_qt_lib::QString;
30-
#[namespace = ""]
31-
type QTime = cxx_qt_lib::QTime;
32-
#[namespace = ""]
33-
type QUrl = cxx_qt_lib::QUrl;
34-
#[namespace = ""]
35-
type QVariant = cxx_qt_lib::QVariant;
36-
379
#[namespace = "cxx_qt::nested_object"]
3810
type NestedObject = crate::cxx_qt_nested_object::FFICppObj;
3911

@@ -76,6 +48,14 @@ mod my_object {
7648
#[cxx_name = "initialiseCpp"]
7749
fn initialise_cpp(cpp: Pin<&mut MyObjectQt>);
7850
}
51+
52+
#[namespace = ""]
53+
unsafe extern "C++" {
54+
include!("cxx-qt-lib/include/qt_types.h");
55+
type QColor = cxx_qt_lib::QColor;
56+
type QPoint = cxx_qt_lib::QPoint;
57+
type QString = cxx_qt_lib::QString;
58+
}
7959
}
8060

8161
pub use self::cxx_qt_my_object::*;
@@ -85,8 +65,6 @@ mod cxx_qt_my_object {
8565
pub type FFICppObj = super::my_object::MyObjectQt;
8666
type UniquePtr<T> = cxx::UniquePtr<T>;
8767

88-
use cxx_qt_lib::QColor;
89-
9068
#[derive(Default)]
9169
pub struct RustObj;
9270

cxx-qt-gen/test_outputs/naming.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ mod my_object {
66
#[cxx_name = "MyObject"]
77
type MyObjectQt;
88

9-
include!("cxx-qt-lib/include/qt_types.h");
10-
#[namespace = ""]
11-
type QColor = cxx_qt_lib::QColor;
12-
#[namespace = ""]
13-
type QDate = cxx_qt_lib::QDate;
14-
#[namespace = ""]
15-
type QDateTime = cxx_qt_lib::QDateTime;
16-
#[namespace = ""]
17-
type QPoint = cxx_qt_lib::QPoint;
18-
#[namespace = ""]
19-
type QPointF = cxx_qt_lib::QPointF;
20-
#[namespace = ""]
21-
type QRect = cxx_qt_lib::QRect;
22-
#[namespace = ""]
23-
type QRectF = cxx_qt_lib::QRectF;
24-
#[namespace = ""]
25-
type QSize = cxx_qt_lib::QSize;
26-
#[namespace = ""]
27-
type QSizeF = cxx_qt_lib::QSizeF;
28-
#[namespace = ""]
29-
type QString = cxx_qt_lib::QString;
30-
#[namespace = ""]
31-
type QTime = cxx_qt_lib::QTime;
32-
#[namespace = ""]
33-
type QUrl = cxx_qt_lib::QUrl;
34-
#[namespace = ""]
35-
type QVariant = cxx_qt_lib::QVariant;
36-
379
#[rust_name = "property_name"]
3810
fn getPropertyName(self: &MyObjectQt) -> i32;
3911
#[rust_name = "set_property_name"]

cxx-qt-gen/test_outputs/passthrough.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,6 @@ pub mod my_object {
66
#[cxx_name = "MyObject"]
77
type MyObjectQt;
88

9-
include!("cxx-qt-lib/include/qt_types.h");
10-
#[namespace = ""]
11-
type QColor = cxx_qt_lib::QColor;
12-
#[namespace = ""]
13-
type QDate = cxx_qt_lib::QDate;
14-
#[namespace = ""]
15-
type QDateTime = cxx_qt_lib::QDateTime;
16-
#[namespace = ""]
17-
type QPoint = cxx_qt_lib::QPoint;
18-
#[namespace = ""]
19-
type QPointF = cxx_qt_lib::QPointF;
20-
#[namespace = ""]
21-
type QRect = cxx_qt_lib::QRect;
22-
#[namespace = ""]
23-
type QRectF = cxx_qt_lib::QRectF;
24-
#[namespace = ""]
25-
type QSize = cxx_qt_lib::QSize;
26-
#[namespace = ""]
27-
type QSizeF = cxx_qt_lib::QSizeF;
28-
#[namespace = ""]
29-
type QString = cxx_qt_lib::QString;
30-
#[namespace = ""]
31-
type QTime = cxx_qt_lib::QTime;
32-
#[namespace = ""]
33-
type QUrl = cxx_qt_lib::QUrl;
34-
#[namespace = ""]
35-
type QVariant = cxx_qt_lib::QVariant;
36-
379
#[rust_name = "number"]
3810
fn getNumber(self: &MyObjectQt) -> i32;
3911
#[rust_name = "set_number"]

0 commit comments

Comments
 (0)