Module: QML

Defined in:
lib/qml/qt.rb,
lib/qml/engine.rb,
lib/qml/access.rb,
lib/qml/signal.rb,
lib/qml/errors.rb,
lib/qml/plugins.rb,
lib/qml/js_util.rb,
lib/qml/version.rb,
lib/qml/js_array.rb,
lib/qml/reactive.rb,
lib/qml/platform.rb,
lib/qml/js_object.rb,
lib/qml/interface.rb,
lib/qml/root_path.rb,
lib/qml/component.rb,
lib/qml/dispatcher.rb,
lib/qml/name_helper.rb,
lib/qml/application.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/exporter.c,
ext/qml/js_object.c,
ext/qml/js_wrapper.c,
ext/qml/js_function.c,
ext/qml/meta_object.c,
ext/qml/application.c,
ext/qml/plugin_loader.c

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.applicationApplication

Returns the instance of Application.

Returns:


54
55
56
57
58
59
# File 'ext/qml/qml.c', line 54

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:


65
66
67
68
69
70
71
# File 'ext/qml/qml.c', line 65

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_implObject

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.


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

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)

42
43
44
45
46
47
48
# File 'ext/qml/qml.c', line 42

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

.next_tick(&block) ⇒ Object

Runs a block asynchronously within the event loop.

QML UI is not thread-safe and can only be accessed from the main thread. Use this method to set results of asynchronous tasks to UI.

Examples:

def on_button_clicked
  Thread.new do
    result = do_task
    QML.next_tick do
      set_result_to_ui(result)
    end
  end
end

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

def next_tick(&block)
  Dispatcher.instance.add_task(&block)
end

.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