@@ -22,7 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
23
23
```
24
24
#[macro_use] extern crate cstr;
25
- extern crate qmetaobject;
26
25
27
26
use qmetaobject::*;
28
27
@@ -88,7 +87,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
87
All the method are provided so you can just implement the QMetaType like this:
89
88
90
89
```rust
91
- # use qmetaobject::QMetaType;
90
+ use qmetaobject::QMetaType;
91
+
92
92
#[derive(Default, Clone)]
93
93
struct MyPoint(u32, u32);
94
94
@@ -115,19 +115,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
115
115
This can be done like so:
116
116
117
117
```
118
- # extern crate qmetaobject;
119
- # use qmetaobject::*;
120
- #[derive(QObject,Default)]
118
+ use qmetaobject::*;
119
+ # use std::cell::RefCell;
120
+
121
+ #[derive(QObject, Default)]
121
122
struct MyAsyncObject {
122
123
base: qt_base_class!(trait QObject),
123
124
result: qt_property!(QString; NOTIFY result_changed),
124
125
result_changed: qt_signal!(),
125
126
recompute_result: qt_method!(fn recompute_result(&self, name: String) {
126
127
let qptr = QPointer::from(&*self);
127
- let set_value = qmetaobject:: queued_callback(move |val: QString| {
128
- qptr.as_pinned().map(|self_ | {
129
- self_ .borrow_mut().result = val;
130
- self_ .borrow().result_changed();
128
+ let set_value = queued_callback(move |val: QString| {
129
+ qptr.as_pinned().map(|this | {
130
+ this .borrow_mut().result = val;
131
+ this .borrow().result_changed();
131
132
});
132
133
});
133
134
std::thread::spawn(move || {
@@ -137,9 +138,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
137
138
}).join();
138
139
})
139
140
}
140
- # let obj = std::cell:: RefCell::new(MyAsyncObject::default());
141
+ # let obj = RefCell::new(MyAsyncObject::default());
141
142
# let mut engine = QmlEngine::new();
142
- # unsafe { qmetaobject:: connect(
143
+ # unsafe { connect(
143
144
# QObject::cpp_construct(&obj),
144
145
# obj.borrow().result_changed.to_cpp_representation(&*obj.borrow()),
145
146
# || engine.quit()
@@ -157,9 +158,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
157
158
#[ macro_use]
158
159
extern crate cpp;
159
160
160
- #[ allow( unused_imports) ]
161
- #[ macro_use]
162
- extern crate qmetaobject_impl;
163
161
#[ doc( hidden) ]
164
162
pub use qmetaobject_impl:: * ;
165
163
@@ -173,7 +171,8 @@ pub use lazy_static::*;
173
171
#[ macro_export]
174
172
macro_rules! qmetaobject_lazy_static { ( $( $t: tt) * ) => { lazy_static!( $( $t) * ) } }
175
173
176
- use std:: cell:: RefCell ;
174
+ use std:: cell:: { RefCell , RefMut } ;
175
+ use std:: ffi:: { CStr , CString } ;
177
176
use std:: os:: raw:: { c_char, c_void} ;
178
177
179
178
pub use qttypes;
@@ -440,11 +439,11 @@ impl<T: QObject + ?Sized> Clone for QPointer<T> {
440
439
/// Same as std::cell::RefMut, but does not allow to move from
441
440
pub struct QObjectRefMut < ' b , T : QObject + ?Sized + ' b > {
442
441
old_value : * mut c_void ,
443
- inner : std :: cell :: RefMut < ' b , T > ,
442
+ inner : RefMut < ' b , T > ,
444
443
}
445
444
446
445
impl < ' b , T : QObject + ?Sized > std:: ops:: Deref for QObjectRefMut < ' b , T > {
447
- type Target = std :: cell :: RefMut < ' b , T > ;
446
+ type Target = RefMut < ' b , T > ;
448
447
449
448
#[ inline]
450
449
fn deref ( & self ) -> & Self :: Target {
@@ -543,7 +542,7 @@ impl<T: QObject + ?Sized> QObjectBox<T> {
543
542
pub fn into_leaked_cpp_ptr < T : QObject > ( obj : T ) -> * mut c_void {
544
543
let b = Box :: new ( RefCell :: new ( obj) ) ;
545
544
let obj_ptr = unsafe { QObject :: cpp_construct ( & b) } ;
546
- std :: boxed :: Box :: into_raw ( b) ;
545
+ Box :: into_raw ( b) ;
547
546
obj_ptr
548
547
}
549
548
@@ -640,7 +639,8 @@ unsafe impl Send for QMetaObject {}
640
639
/// The trait needs to be like the QObject trait, see the documentation of the QObject trait.
641
640
///
642
641
/// ```
643
- /// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
642
+ /// use qmetaobject::*;
643
+ ///
644
644
/// #[derive(QObject)]
645
645
/// struct Foo {
646
646
/// base : qt_base_class!(trait QObject),
@@ -670,7 +670,8 @@ macro_rules! qt_base_class {
670
670
/// `ALIAS` followed by an identifier allow to give a different name than the actual field name.
671
671
///
672
672
/// ```
673
- /// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
673
+ /// use qmetaobject::*;
674
+ ///
674
675
/// #[derive(QObject)]
675
676
/// struct Foo {
676
677
/// base: qt_base_class!(trait QObject),
@@ -696,7 +697,8 @@ macro_rules! qt_property {
696
697
/// Can be used within a struct that derives from QObject or QGadget
697
698
///
698
699
/// ```
699
- /// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
700
+ /// use qmetaobject::*;
701
+ ///
700
702
/// #[derive(QObject)]
701
703
/// struct Foo {
702
704
/// base: qt_base_class!(trait QObject),
@@ -726,7 +728,8 @@ macro_rules! qt_method {
726
728
/// To be used within a struct that derives from QObject
727
729
///
728
730
/// ```
729
- /// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject;
731
+ /// use qmetaobject::*;
732
+ ///
730
733
/// #[derive(QObject)]
731
734
/// struct Foo {
732
735
/// base: qt_base_class!(trait QObject),
@@ -748,15 +751,16 @@ macro_rules! qt_signal {
748
751
/// the IID
749
752
///
750
753
/// ```
751
- /// # #[macro_use] extern crate qmetaobject;
752
- /// # use qmetaobject::qtdeclarative::QQmlExtensionPlugin;
754
+ /// use qmetaobject::*;
755
+ /// # use std::ffi::CStr;
756
+ ///
753
757
/// #[derive(Default, QObject)]
754
758
/// struct MyPlugin {
755
759
/// base: qt_base_class!(trait QQmlExtensionPlugin),
756
760
/// plugin: qt_plugin!("org.qt-project.Qt.QQmlExtensionInterface/1.0")
757
761
/// }
758
762
/// # impl QQmlExtensionPlugin for MyPlugin {
759
- /// # fn register_types(&mut self, uri: &std::ffi:: CStr) {}
763
+ /// # fn register_types(&mut self, uri: &CStr) {}
760
764
/// # }
761
765
/// ```
762
766
#[ macro_export]
@@ -841,8 +845,8 @@ where
841
845
/// callback will not be recieved.
842
846
///
843
847
/// ```
844
- /// # extern crate qmetaobject;
845
- /// # use qmetaobject::queued_callback;
848
+ /// use qmetaobject::queued_callback ;
849
+ ///
846
850
/// let callback = queued_callback(|()| println!("hello from main thread"));
847
851
/// std::thread::spawn(move || {callback(());}).join();
848
852
/// ```
@@ -989,10 +993,9 @@ pub const USER_ROLE: i32 = 0x0100;
989
993
/// ```
990
994
/// then the following Rust code:
991
995
/// ```
992
- /// # extern crate qmetaobject;
993
- /// # use qmetaobject::qrc;
996
+ /// use qmetaobject::qrc;
994
997
/// # // For maintainers: this is actually tested against real files.
995
- /// // private fn, and base directory shortcut
998
+ /// // private fn, base directory shortcut
996
999
/// qrc!(my_resource_1,
997
1000
/// "tests/qml" as "foo1" {
998
1001
/// "main.qml",
@@ -1016,6 +1019,7 @@ pub const USER_ROLE: i32 = 0x0100;
1016
1019
/// # fn use_resource(_r: &str) {
1017
1020
/// # // at the time of writing, it is the only way to test the existence of a resource.
1018
1021
/// # use qmetaobject::*;
1022
+ /// #
1019
1023
/// # let mut engine = QmlEngine::new();
1020
1024
/// # let mut c = QmlComponent::new(&engine);
1021
1025
/// # c.load_url(QUrl::from(QString::from("qrc:/foo2/baz/Foo.qml")), CompilationMode::PreferSynchronous);
0 commit comments