Module: QML

Defined in:
lib/qml/qt.rb,
lib/qml/init.rb,
lib/qml/access.rb,
lib/qml/engine.rb,
lib/qml/errors.rb,
lib/qml/context.rb,
lib/qml/plugins.rb,
lib/qml/version.rb,
lib/qml/platform.rb,
lib/qml/component.rb,
lib/qml/root_path.rb,
lib/qml/wrappable.rb,
lib/qml/data/error.rb,
lib/qml/dispatcher.rb,
lib/qml/application.rb,
lib/qml/meta_object.rb,
lib/qml/name_helper.rb,
lib/qml/dispatchable.rb,
lib/qml/geometry/size.rb,
lib/qml/plugin_loader.rb,
lib/qml/geometry/point.rb,
lib/qml/image_provider.rb,
lib/qml/qt_object_base.rb,
lib/qml/reactive/error.rb,
lib/qml/data/list_model.rb,
lib/qml/error_converter.rb,
lib/qml/reactive/object.rb,
lib/qml/reactive/signal.rb,
lib/qml/data/array_model.rb,
lib/qml/data/query_model.rb,
lib/qml/reactive/bindable.rb,
lib/qml/reactive/property.rb,
lib/qml/geometry/rectangle.rb,
lib/qml/reactive/signal_spy.rb,
lib/qml/reactive/chained_signal.rb,
lib/qml/reactive/unbound_signal.rb,
lib/qml/reactive/simple_property.rb,
lib/qml/reactive/unbound_property.rb,
lib/qml/reactive/signals/map_signal.rb,
lib/qml/reactive/signals/merge_signal.rb,
lib/qml/test_util/object_life_checker.rb,
lib/qml/reactive/signals/select_signal.rb

Defined Under Namespace

Modules: Access, Data, Dispatchable, ErrorConverter, Geometry, NameHelper, Platform, Plugins, Reactive, TestUtil, Wrappable Classes: AccessError, AlreadyInitializedError, Application, ApplicationError, Component, Context, ConversionError, CppError, Dispatcher, Engine, EngineError, ImageProvider, InvalidThreadError, MetaObject, MethodError, PluginError, PluginLoader, PropertyError, QMLError, Qt, QtObjectBase, QtObjectError, QtProperty, QtPropertyBase, QtSignal, SignalError, UninitializedError

Constant Summary collapse

VERSION =
'0.0.6'
ROOT_PATH =
Pathname.new(__FILE__) + '../../..'

Class Method Summary collapse

Class Method Details

.applicationApplication

Returns the instance of Application.

Returns:



111
112
113
# File 'lib/qml/application.rb', line 111

def application
  Application.instance
end

.engineEngine

Returns the instance of Engine.

Returns:

See Also:



50
51
52
# File 'lib/qml/engine.rb', line 50

def engine
  Kernel.engine
end

.init(opts = {}) ⇒ Object

Initializes ruby-qml.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :offscreen (Boolean) — default: false

    set this to true to run application offscreen (without GUI)



11
12
13
14
15
16
17
18
# File 'lib/qml/init.rb', line 11

def init(opts = {})
  opts = {offscreen: false}.merge opts
  fail AlreadyInitializedError, "ruby-qml already initialized" if initialized?
  argv = [$PROGRAM_NAME]
  argv += %w{-platform offscreen} if opts[:offscreen]
  Kernel.init(argv)
  @on_init.each(&:call)
end

.initialized?Boolean

Returns whether #init is already called.

Returns:

  • (Boolean)

    whether #init is already called.



4
5
6
# File 'lib/qml/init.rb', line 4

def initialized?
  Kernel.initialized?
end

.later(&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.later do
      set_result_to_ui(result)
    end
  end
end

See Also:



65
66
67
# File 'lib/qml/dispatcher.rb', line 65

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

.on_init { ... } ⇒ Object

Registers a block to be called just after #init is called.

Yields:



24
25
26
# File 'lib/qml/init.rb', line 24

def on_init(&block)
  @on_init << block
end

.runApplication

Call init if ruby-qml is not initialized, then yields the application instance and then call QML::Application#exec.

Examples:

QML.run do |app|
  app.context[:foo] = 'foo'
  app.load_path Pathname(__FILE__) + '../main.qml'
end

Returns:



122
123
124
125
126
127
128
# File 'lib/qml/application.rb', line 122

def run
  QML.init unless QML.initialized?
  Application.instance.tap do |app|
    yield app
    app.exec
  end
end