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/class_builder.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, ClassBuilder, 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.5'
ROOT_PATH =
Pathname.new(__FILE__) + '../../..'

Class Method Summary collapse

Class Method Details

.applicationApplication .applicationApplication

Overloads:

See Also:



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

def application
  if block_given?
    QML.init unless QML.initialized?
    Application.instance.tap do |app|
      yield app
      app.exec
    end
  else
    Application.instance
  end
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:



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

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