Module: QML

Defined in:
lib/qml/qt.rb,
lib/qml/access.rb,
lib/qml/engine.rb,
lib/qml/errors.rb,
lib/qml/signal.rb,
lib/qml/js_util.rb,
lib/qml/plugins.rb,
lib/qml/version.rb,
lib/qml/js_array.rb,
lib/qml/platform.rb,
lib/qml/reactive.rb,
lib/qml/component.rb,
lib/qml/interface.rb,
lib/qml/js_object.rb,
lib/qml/root_path.rb,
lib/qml/application.rb,
lib/qml/name_helper.rb,
lib/qml/proc_access.rb,
lib/qml/plugin_loader.rb,
lib/qml/data/list_model.rb,
lib/qml/data/array_model.rb,
lib/qml/data/query_model.rb,
lib/qml/data/list_model_access.rb,
ext/qml/qml.c,
ext/qml/engine.c,
ext/qml/js_array.c,
ext/qml/js_object.c,
ext/qml/js_wrapper.c,
ext/qml/meta_class.c,
ext/qml/application.c,
ext/qml/js_function.c,
ext/qml/plugin_loader.c

Defined Under Namespace

Modules: Access, Interface, JSUtil, NameHelper, Platform, Plugins, Reactive Classes: AccessError, Application, ArrayModel, Component, Engine, JSArray, JSFunction, JSObject, JSWrapper, ListModel, ListModelAccess, MetaClass, PluginError, PluginLoader, ProcAccess, QMLError, QueryModel, Signal

Constant Summary collapse

VERSION =
'1.0.2'
ROOT_PATH =
Pathname.new(__FILE__) + '../../..'
INIT_BLOCKS =
[]

Class Method Summary collapse

Class Method Details

.applicationApplication

Returns the instance of Application.

Returns:


52
53
54
55
56
57
# File 'ext/qml/qml.c', line 52

static VALUE qml_application(VALUE module) {
    if (NIL_P(rbqml_application)) {
        rb_raise(rb_eRuntimeError, "QML not yet initialized");
    }
    return rbqml_application;
}

.engineEngine

Returns the instance of Engine.

Returns:


63
64
65
66
67
68
# File 'ext/qml/qml.c', line 63

static VALUE qml_engine(VALUE module) {
    if (NIL_P(rbqml_engine)) {
        rb_raise(rb_eRuntimeError, "QML not yet initialized");
    }
    return rbqml_engine;
}

.init(args = []) ⇒ Object

Initializes ruby-qml.

Parameters:

  • args (Array<String>) (defaults to: [])

    Arguments to pass to the application


63
64
65
# File 'lib/qml/application.rb', line 63

def init(args = [])
  init_impl(args)
end

.init_impl(args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'ext/qml/qml.c', line 21

static VALUE qml_init(VALUE module, VALUE args) {
    if (!NIL_P(rbqml_application)) {
        rb_raise(rb_eRuntimeError, "QML already initialized");
    }

    rbqml_application = rb_funcall(rbqml_cApplication, rb_intern("new"), 1, args);
    rbqml_engine = rb_funcall(rbqml_cEngine, rb_intern("new"), 0);

    rb_gc_register_address(&rbqml_application);
    rb_gc_register_address(&rbqml_engine);

    VALUE blocks = rb_const_get(module, rb_intern("INIT_BLOCKS"));
    for (int i = 0; i < RARRAY_LEN(blocks); ++i) {
        rb_proc_call(RARRAY_AREF(blocks, i), rb_ary_new());
    }

    return module;
}

.initialized?Boolean

Returns:

  • (Boolean)

40
41
42
43
44
45
46
# File 'ext/qml/qml.c', line 40

static VALUE qml_initialized_p(VALUE module) {
    if (NIL_P(rbqml_application)) {
        return Qfalse;
    } else {
        return Qtrue;
    }
}

.next_tick(*args) ⇒ Object


83
84
85
86
87
88
89
90
# File 'ext/qml/qml.c', line 83

static VALUE qml_next_tick(int argc, VALUE *argv, VALUE module) {
    VALUE block;
    rb_scan_args(argc, argv, "&", &block);
    rbqml_retain_value(block);

    qmlbind_next_tick(nextTickCallback, (void *)block);
    return block;
}

.on_init(&block) ⇒ Object


57
58
59
# File 'lib/qml/application.rb', line 57

def on_init(&block)
  INIT_BLOCKS << block
end

.qtJSObject

Returns QML Qt namespace object.

Examples:

def set_app_name
  QML.qt.application.name = 'appname'
end

Returns:

  • (JSObject)

    QML Qt namespace object

See Also:


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/qml/qt.rb', line 11

def qt
  @qt ||= begin
    component = QML::Component.new data: <<-QML
      import QtQuick 2.0
      QtObject {
        function getQt() {
          return Qt;
        }
      }
    QML
    component.create.getQt
  end
end

.runApplication

Creates an Application, yields it and then call QML::Application#exec.

Examples:

QML.run do |app|
  app.load_path Pathname(__FILE__) + '../main.qml'
end

Returns:


73
74
75
76
77
78
79
# File 'lib/qml/application.rb', line 73

def run
  QML.init
  QML.application.tap do |app|
    yield app
    app.exec
  end
end