File tree 6 files changed +90
-1
lines changed
tests/qt_types_standalone
6 files changed +90
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
17
17
### Added
18
18
19
19
- Support for further types: ` QLine ` , ` QLineF ` , ` QImage `
20
+ - ` internal_pointer_mut() ` function on ` QModelIndex `
21
+ - ` c_void ` in CXX-Qt-lib for easy access to ` void * `
20
22
21
23
## [ 0.6.0] ( https://github.com/KDAB/cxx-qt/compare/v0.5.3...v0.6.0 ) - 2023-11-17
22
24
Original file line number Diff line number Diff line change 14
14
namespace rust {
15
15
namespace cxxqtlib1 {
16
16
17
+ using c_void = void ;
18
+
17
19
template <typename T, typename ... Args>
18
20
T
19
21
construct (Args... args)
Original file line number Diff line number Diff line change @@ -96,3 +96,33 @@ pub use qvariant::{QVariant, QVariantValue};
96
96
97
97
mod qvector;
98
98
pub use qvector:: { QVector , QVectorElement } ;
99
+
100
+ #[ cxx:: bridge]
101
+ mod ffi {
102
+ #[ namespace = "rust::cxxqtlib1" ]
103
+ unsafe extern "C++" {
104
+ include ! ( "cxx-qt-lib/common.h" ) ;
105
+ type c_void ;
106
+ }
107
+ }
108
+
109
+ /// This is a workaround for CXX missing support for `*mut c_void`/`*const c_void` types.
110
+ ///
111
+ /// To use this type add this to your bridge:
112
+ /// ```rust
113
+ /// # #[cxx::bridge]
114
+ /// # mod ffi {
115
+ /// #
116
+ /// #[namespace = "rust::cxxqtlib1"]
117
+ /// unsafe extern "C++" {
118
+ /// include!("cxx-qt-lib/common.h");
119
+ /// type c_void = cxx_qt_lib::c_void;
120
+ /// }
121
+ /// #
122
+ /// # }
123
+ /// #
124
+ /// # fn main() {}
125
+ /// ```
126
+ ///
127
+ /// See: <https://github.com/dtolnay/cxx/issues/1049>
128
+ pub use ffi:: c_void;
Original file line number Diff line number Diff line change @@ -34,11 +34,16 @@ mod ffi {
34
34
/// Returns the sibling at row for the current column. If there is no sibling at this position, an invalid QModelIndex is returned.
35
35
#[ rust_name = "sibling_at_row" ]
36
36
fn siblingAtRow ( self : & QModelIndex , row : i32 ) -> QModelIndex ;
37
+
38
+ /// Returns a `*mut c_void` pointer used by the model to associate the index with the internal data structure.
39
+ #[ rust_name = "internal_pointer_mut" ]
40
+ fn internalPointer ( self : & QModelIndex ) -> * mut c_void ;
37
41
}
38
42
39
43
#[ namespace = "rust::cxxqtlib1" ]
40
44
unsafe extern "C++" {
41
45
include ! ( "cxx-qt-lib/common.h" ) ;
46
+ type c_void = crate :: c_void ;
42
47
43
48
#[ doc( hidden) ]
44
49
#[ rust_name = "qmodelindex_init_default" ]
Original file line number Diff line number Diff line change 6
6
// SPDX-License-Identifier: MIT OR Apache-2.0
7
7
#pragma once
8
8
9
+ #include < QtCore/QAbstractListModel>
9
10
#include < QtCore/QModelIndex>
10
11
#include < QtCore/QStringListModel>
11
12
#include < QtTest/QTest>
12
13
13
14
#include " cxx-qt-gen/qmodelindex_cxx.cxx.h"
14
15
15
- class QModelIndexTest : public QObject
16
+ // We subclass from QAbstractListModel to have a valid model to use for
17
+ // access to createIndex();
18
+ class QModelIndexTest : public QAbstractListModel
16
19
{
17
20
Q_OBJECT
18
21
22
+ public:
23
+ int rowCount (const QModelIndex& parent = QModelIndex()) const override
24
+ {
25
+ return 0 ;
26
+ }
27
+
28
+ QVariant data (const QModelIndex& index,
29
+ int role = Qt::DisplayRole) const override
30
+ {
31
+ return QVariant ();
32
+ }
33
+
19
34
private Q_SLOTS:
20
35
void construct ()
21
36
{
@@ -38,4 +53,23 @@ private Q_SLOTS:
38
53
QCOMPARE (c.isValid (), true );
39
54
QCOMPARE (c.row (), 0 );
40
55
}
56
+
57
+ void internalPointer ()
58
+ {
59
+ const auto index = createIndex (0 , 0 , (void *)&my_data);
60
+
61
+ auto pointer = internal_pointer_qmodelindex (index );
62
+ QCOMPARE ((int *)pointer, &my_data);
63
+ }
64
+
65
+ void internalId ()
66
+ {
67
+ const auto index = createIndex (0 , 0 , (quintptr)1234 );
68
+
69
+ auto id = internal_id_qmodelindex (index );
70
+ QCOMPARE (id, 1234 );
71
+ }
72
+
73
+ private:
74
+ int my_data = 42 ;
41
75
};
Original file line number Diff line number Diff line change @@ -12,10 +12,18 @@ mod qmodelindex_cxx {
12
12
type QModelIndex = cxx_qt_lib:: QModelIndex ;
13
13
}
14
14
15
+ #[ namespace = "rust::cxxqtlib1" ]
16
+ unsafe extern "C++" {
17
+ include ! ( "cxx-qt-lib/common.h" ) ;
18
+ type c_void = cxx_qt_lib:: c_void ;
19
+ }
20
+
15
21
extern "Rust" {
16
22
fn construct_qmodelindex ( ) -> QModelIndex ;
17
23
fn read_qmodelindex ( i : & QModelIndex ) -> bool ;
18
24
fn clone_qmodelindex ( i : & QModelIndex ) -> QModelIndex ;
25
+ fn internal_pointer_qmodelindex ( i : & QModelIndex ) -> * mut c_void ;
26
+ fn internal_id_qmodelindex ( i : & QModelIndex ) -> usize ;
19
27
}
20
28
}
21
29
@@ -30,3 +38,11 @@ fn read_qmodelindex(i: &QModelIndex) -> bool {
30
38
fn clone_qmodelindex ( i : & QModelIndex ) -> QModelIndex {
31
39
i. clone ( )
32
40
}
41
+
42
+ fn internal_pointer_qmodelindex ( i : & QModelIndex ) -> * mut qmodelindex_cxx:: c_void {
43
+ i. internal_pointer_mut ( )
44
+ }
45
+
46
+ fn internal_id_qmodelindex ( i : & QModelIndex ) -> usize {
47
+ i. internal_id ( )
48
+ }
You can’t perform that action at this time.
0 commit comments