Skip to content

Instantly share code, notes, and snippets.

@timsueberkrueb
Last active January 6, 2019 12:59
Show Gist options
  • Save timsueberkrueb/e4f2e626ee55f4bf1927554093d8a389 to your computer and use it in GitHub Desktop.
Save timsueberkrueb/e4f2e626ee55f4bf1927554093d8a389 to your computer and use it in GitHub Desktop.
Qt & Rust & Ubuntu touch
diff --git a/qmetaobject/src/qmetatype.rs b/qmetaobject/src/qmetatype.rs
index bc20a98..25ff21a 100644
--- a/qmetaobject/src/qmetatype.rs
+++ b/qmetaobject/src/qmetatype.rs
@@ -258,15 +258,9 @@ impl QMetaType for QVariant {
}
qdeclare_builtin_metatype!{QModelIndex => 42}
-#[cfg(target_pointer_width = "32")]
qdeclare_builtin_metatype!{isize => 32} // That's QMetaType::Long
-#[cfg(target_pointer_width = "32")]
qdeclare_builtin_metatype!{usize => 35} // That's QMetaType::ULong
// long on 64bit windows is still 32bit, so use LongLong
-#[cfg(target_pointer_width = "64")]
-qdeclare_builtin_metatype!{isize => 4}
-#[cfg(target_pointer_width = "64")]
-qdeclare_builtin_metatype!{usize => 5}
/// Internal trait used to pass or read the type in a Q_PROPERTY
///
diff --git a/qmetaobject_impl/src/qobject_impl.rs b/qmetaobject_impl/src/qobject_impl.rs
index e9178d9..ca17a3a 100644
--- a/qmetaobject_impl/src/qobject_impl.rs
+++ b/qmetaobject_impl/src/qobject_impl.rs
@@ -118,20 +118,13 @@ struct MetaObject {
impl MetaObject {
fn build_string_data(&self) -> Vec<u8> {
let mut result: Vec<u8> = Vec::new();
- #[cfg(target_pointer_width = "64")]
- let sizeof_qbytearraydata = 24;
- #[cfg(target_pointer_width = "32")]
let sizeof_qbytearraydata = 16;
let mut ofs = sizeof_qbytearraydata * self.string_data.len() as i32;
for s in self.string_data.iter() {
result.extend_from_slice(&write_u32(-1)); // ref (-1)
result.extend_from_slice(&write_u32(s.len() as i32)); // size
result.extend_from_slice(&write_u32(0)); // alloc / capacityReserved
- #[cfg(target_pointer_width = "64")]
- result.extend_from_slice(&write_u32(0)); // padding
result.extend_from_slice(&write_u32(ofs)); // offset (LSB)
- #[cfg(target_pointer_width = "64")]
- result.extend_from_slice(&write_u32(0)); // offset (MSB)
ofs += s.len() as i32 + 1; // +1 for the '\0'
ofs -= sizeof_qbytearraydata;
diff --git a/Cargo.toml b/Cargo.toml
index 88dcda5..11e72ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,5 +5,5 @@ authors = ["Tim Süberkrüb <[email protected]>"]
edition = "2018"
[dependencies]
-qmetaobject = "0.0.4"
+qmetaobject = { path="qmetaobject-rs/qmetaobject" }
cstr = "0.1.0"
diff --git a/src/main.rs b/src/main.rs
index 394edbe..5cd807a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,14 +5,20 @@ use qmetaobject::*;
#[derive(QObject,Default)]
struct Greeter {
base : qt_base_class!(trait QObject),
- //name : qt_property!(QString; NOTIFY name_changed),
- //name_changed : qt_signal!(),
- /*compute_greetings : qt_method!(fn compute_greetings(&self, verb : String) -> QString {
+ name : qt_property!(QString; NOTIFY name_changed),
+ name_changed : qt_signal!(),
+ compute_greetings : qt_method!(fn compute_greetings(&self, verb : String) -> QString {
return (verb + " " + &self.name.to_string()).into()
- })*/
+ })
}
fn main() {
+ #[cfg(target_pointer_width = "32")]
+ println!("Running on 32-bit");
+
+ #[cfg(target_pointer_width = "64")]
+ println!("Running on 64-bit");
+
qml_register_type::<Greeter>(cstr!("Greeter"), 1, 0, cstr!("Greeter"));
let mut engine = QmlEngine::new();
engine.load_data(r#"import QtQuick 2.6; import QtQuick.Window 2.0;
@@ -20,7 +26,7 @@ import Greeter 1.0
Window {
visible: true;
Greeter { id: greeter; /*name: 'World';*/ }
- Text { anchors.centerIn: parent; text: greeter.compute_greetings('hello'); }
+ Text { anchors.centerIn: parent; text: greeter.compute_greetings('hello, wow!'); }
}"#.into());
engine.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment