<repo_name>EleDiaz/qml-rust<file_sep>/examples/listmodel_macro.rs
#[macro_use]
extern crate qml;

use qml::*;

Q_LISTMODEL!{
    pub QTestModel {
        name: String,
        number: i32,
    }
}

fn main() {
    let mut qqae = QmlEngine::new();
    let mut qalm = QTestModel::new();
    qalm.insert_row("John".into(), 42);
    qalm.insert_row("Oak".into(), 505);
    // `&QTestModel` implements `Into<QVariant>`
    qqae.set_and_store_property("listModel", qalm.get_qvar());

    qqae.load_file("examples/listmodel.qml");
    qalm.set_data(vec![("OMG".into(), 13317), ("HACKED".into(), 228)]);
    qqae.exec();
    qqae.quit();
}
<file_sep>/build.rs
extern crate pkg_config;
use std::env;
use std::process::Command;
use std::path::*;
use pkg_config::*;

fn main() {
    Command::new("sh")
        .arg("build_lib.sh")
        .output()
        .unwrap_or_else(|e| panic!("failed to execute process: {}", e));
    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let path = Path::new(&manifest_dir).join("DOtherSide").join("build").join("lib");

    println!("cargo:rustc-link-search=native={}", path.display());
    println!("cargo:rerun-if-changed={}", path.display());
    println!("cargo:rustc-link-lib=static=DOtherSideStatic");
    println!("cargo:rustc-link-lib=dylib=stdc++");

    Config::new().probe("Qt5Core Qt5Gui Qt5Qml Qt5Quick Qt5Widgets").unwrap();
}
<file_sep>/src/lib.rs
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
extern crate libc;
#[macro_use]
extern crate lazy_static;

mod qmlengine;
mod qvariant;
mod qabstractlistmodel;
mod qinthasharray;
mod utils;
mod qmodelindex;
mod types;
mod qurl;
mod qobject;
mod qmeta;
mod qtypes;
#[macro_use]
mod macros;
mod qmlregister;

pub use qmlengine::QmlEngine;
pub use qvariant::QVariant;
pub use qabstractlistmodel::{QModel, QAbstractListModel, QListModel};
pub use qmodelindex::QModelIndex;
pub use qobject::QObject;
pub use qmeta::{QObjectMacro, emit_signal};
pub use qtypes::*;
pub use qmlregister::QMLRegisterable;

#[doc(hidden)]
pub use libc::c_void;

#[doc(hidden)]
pub use qmlregister::{register_qml_type, register_qml_singleton_type};
<file_sep>/build_lib.sh
git clone https://github.com/filcuc/DOtherSide.git --single-branch --depth 1
cd DOtherSide
rm -rf build
mkdir build
cd build

cmake ..
make DOtherSideStatic
<file_sep>/examples/qobjects.rs
#[macro_use]
extern crate qml;

use qml::*;

pub struct Test;

impl Test {
    pub fn launchGoose(&self, i: i32, i2: String) -> Option<&QVariant> {
        println!("GOOSE HI from {} and {}", i2, i);
        None
    }
}

Q_OBJECT!(
pub Test as QTest{
    signals:
 fn testname (a: i32, b: i32);
    slots:
 fn launchGoose(i: i32, launchText: String);
    properties:
});

fn main() {
    let mut qqae = QmlEngine::new();
    let mut qtest = QTest::new(Test);
    qtest.testname(54, 55);
    qtest.qslot_call("launchGoose",
                     vec![42.into(), "QML Rust".to_string().into()]);
    println!("{:?}", qtest.qmeta());
}
<file_sep>/examples/qabstractlistmodel.rs

#[macro_use] extern crate qml;
use qml::*;
pub struct SimpleList(Vec<i32>);

impl QModel for SimpleList {
    fn row_count(&self) -> i32 {
        self.0.len() as i32
    }

    fn data(&self, index: QModelIndex, role: i32) -> QVariant {
        QVariant::from(self.0[index.row() as usize])
    }

    fn roles_names(&self) -> Vec<String> {
        vec!["name".to_string(), "number".to_string()]
    }

    fn flags(&self, index: QModelIndex) -> i32 {
        0
    }
}

// ...

fn main() {
    let mut qqae = QmlEngine::new();
    let model = SimpleList(vec![1,74,7,8,75]);
    let mut qalm = QAbstractListModel::new(&model);
    qqae.set_property("listModel", &qalm.get_qvar());

    qqae.load_file("examples/listmodel.qml");
    qqae.exec();
    qqae.quit();
}
<file_sep>/examples/listmodel.rs
#[macro_use]
extern crate qml;

use qml::*;

fn main() {
    let qqae = QmlEngine::new();
    let mut qalm = QListModel::new(&["name", "number"]);
    qalm.insert_row(qvarlist!["John", 42].into_iter());
    qalm.insert_row(qvarlist!["Oak", 505].into_iter());
    qqae.set_property("listModel", &qalm.get_qvar());

    qqae.load_file("examples/listmodel.qml");
    qalm.set_data(vec![qvarlist!["OMG", 13317], qvarlist!["HACKED", 228]]);
    qqae.exec();
    qqae.quit();
}
