Skip to content

Commit c6ecbcd

Browse files
authored
Merge pull request #137 from ratijas/shorten-uses
Shorten paths and modernize imports
2 parents ad28e6c + dc56c9d commit c6ecbcd

30 files changed

+213
-206
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ Presentation Blog Post: https://woboq.com/blog/qmetaobject-from-rust.html
1818
## Overview
1919

2020
```rust
21-
#[macro_use] extern crate cstr;
22-
extern crate qmetaobject;
23-
21+
use cstr::cstr;
2422
use qmetaobject::*;
2523

2624
// The `QObject` custom derive macro allows to expose a class to Qt and QML
27-
#[derive(QObject,Default)]
25+
#[derive(QObject, Default)]
2826
struct Greeter {
2927
// Specify the base class with the qt_base_class macro
3028
base: qt_base_class!(trait QObject),

examples/graph/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FO
1515
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1616
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
*/
18-
extern crate cpp_build;
1918

2019
fn main() {
2120
let qt_include_path = std::env::var("DEP_QT_INCLUDE_PATH").unwrap();

examples/graph/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#![allow(non_snake_case)]
22
#![allow(unused_variables)]
3-
#[macro_use]
4-
extern crate qmetaobject;
3+
4+
use cpp::cpp;
5+
use cstr::cstr;
6+
57
use qmetaobject::scenegraph::*;
68
use qmetaobject::*;
7-
#[macro_use]
8-
extern crate cstr;
9-
#[macro_use]
10-
extern crate cpp;
119

1210
mod nodes;
1311

examples/graph/src/nodes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use cpp::cpp;
2+
13
use qmetaobject::scenegraph::SGNode;
2-
use qmetaobject::{QColor, QQuickItem, QRectF};
4+
use qmetaobject::{qrc, QQuickItem};
5+
use qttypes::{QColor, QRectF};
36

47
qrc! {
58
init_resource,

examples/qmlextensionplugins/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ name = "qmlqtimeexampleplugin"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
qmetaobject = { path = "../../qmetaobject"}
12+
qmetaobject = { path = "../../qmetaobject" }
1313
chrono = "^0.4"
14+
cstr = "0.2"

examples/qmlextensionplugins/src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
extern crate qmetaobject;
2-
use qmetaobject::*;
3-
extern crate chrono;
4-
use chrono::Timelike;
1+
use std::ffi::CStr;
52
use std::sync::{Arc, Condvar, Mutex};
63
use std::thread::JoinHandle;
74

5+
use chrono::Timelike;
6+
use cstr::cstr;
7+
8+
use qmetaobject::*;
9+
810
#[derive(Default)]
911
struct AbortCondVar {
1012
is_aborted: Mutex<bool>,
@@ -75,13 +77,8 @@ struct QExampleQmlPlugin {
7577
}
7678

7779
impl QQmlExtensionPlugin for QExampleQmlPlugin {
78-
fn register_types(&mut self, uri: &std::ffi::CStr) {
79-
//assert_eq!(uri, std::ffi::CStr::from_bytes_with_nul(b"TimeExample\0"));
80-
qml_register_type::<TimeModel>(
81-
uri,
82-
1,
83-
0,
84-
std::ffi::CStr::from_bytes_with_nul(b"Time\0").unwrap(),
85-
);
80+
fn register_types(&mut self, uri: &CStr) {
81+
//assert_eq!(uri, cstr!("TimeExample"));
82+
qml_register_type::<TimeModel>(uri, 1, 0, cstr!("Time"));
8683
}
8784
}

examples/todos/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ edition = "2018"
55
authors = ["Olivier Goffart <ogoffart@woboq.com>"]
66

77
[dependencies]
8-
qmetaobject = { path = "../../qmetaobject"}
8+
qmetaobject = { path = "../../qmetaobject" }
9+
cstr = "0.2"

examples/todos/src/implementation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
* You should have received a copy of the GNU General Public License
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
21-
use qmetaobject::*;
2221
use std::collections::HashMap;
2322

23+
use qmetaobject::*;
24+
2425
#[derive(Default, Clone)]
2526
struct TodosItem {
2627
completed: bool,

examples/todos/src/main.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
extern crate qmetaobject;
2-
use qmetaobject::*;
1+
use cstr::cstr;
32

4-
use std::ffi::CStr;
3+
use qmetaobject::*;
54

65
mod implementation;
76

@@ -13,12 +12,7 @@ qrc!(my_resource,
1312

1413
fn main() {
1514
my_resource();
16-
qml_register_type::<implementation::Todos>(
17-
CStr::from_bytes_with_nul(b"RustCode\0").unwrap(),
18-
1,
19-
0,
20-
CStr::from_bytes_with_nul(b"Todos\0").unwrap(),
21-
);
15+
qml_register_type::<implementation::Todos>(cstr!("RustCode"), 1, 0, cstr!("Todos"));
2216
let mut engine = QmlEngine::new();
2317
engine.load_file("qrc:/todos/qml/main.qml".into());
2418
engine.exec();

examples/webengine/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate qmetaobject;
21
use qmetaobject::*;
32

43
qrc!(my_resource,

0 commit comments

Comments
 (0)