Class: QML::Application

Inherits:
QtObjectBase show all
Defined in:
lib/qml/application.rb,
lib/qml/application.rb

Overview

Application represents a Qt application instance. It provides the event loop and manages Application-level configurations.

See Also:

Instance Attribute Summary

Attributes inherited from QtObjectBase

#pointer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from QtObjectBase

#inspect, #managed=, #managed?, #prefer_managed, #qml_eval

Methods included from Reactive::Object

included, #properties, #property, #signal, #signals

Methods included from Reactive::Object::ClassMethods

#alias_property, #alias_signal, #instance_properties, #instance_property, #instance_signal, #instance_signals, #on, #on_changed, #property, #signal, #variadic_signal

Methods included from Dispatchable

#later

Constructor Details

#initializeApplication

Returns a new instance of Application.



26
27
28
29
# File 'lib/qml/application.rb', line 26

def initialize
  super()
  @extension = Plugins.core.createApplicationExtension(self)
end

Class Method Details

.instanceApplication

Returns The application instance.

Returns:



13
14
15
# File 'lib/qml/application.rb', line 13

def self.instance
  Kernel.application
end

.newObject

Note:

This method cannot be called because QML::Application is singleton.



22
23
24
# File 'lib/qml/application.rb', line 22

def self.new
  fail ApplicationError, "cannot create Application instance manually"
end

.notify_error(error) ⇒ Object



17
18
19
# File 'lib/qml/application.rb', line 17

def self.notify_error(error)
  instance.notify_error(error)
end

Instance Method Details

#collect_garbageObject

Runs garbage collection of Ruby and QML and deletes unused objects.



94
95
96
97
98
# File 'lib/qml/application.rb', line 94

def collect_garbage
  ::GC.start
  engine.collect_garbage
  force_deferred_deletes
end

#contextContext

Returns The root context of the engine.

Returns:

  • (Context)

    The root context of the engine.

See Also:



38
39
40
# File 'lib/qml/application.rb', line 38

def context
  engine.context
end

#engineEngine

Returns The engine of the application.

Returns:

  • (Engine)

    The engine of the application.



32
33
34
# File 'lib/qml/application.rb', line 32

def engine
  Kernel.engine
end

#execObject

Starts the event loop of the application. This method never returns until the application quits.



79
80
81
# File 'lib/qml/application.rb', line 79

def exec
  @extension.exec
end

#force_deferred_deletesObject



89
90
91
# File 'lib/qml/application.rb', line 89

def force_deferred_deletes
  @extension.force_deferred_deletes
end

#load(opts) ⇒ Object

Loads a QML file. The loaded component can be accessed by #root_component

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :data (String)
  • :path (String)

See Also:



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

def load(opts)
  @root_component = Component.new(data: opts[:data], path: opts[:path])
  @root = @root_component.create
end

#load_data(data) ⇒ Object

Loads a QML file from string data.

See Also:



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

def load_data(data)
  load(data: data)
end

#load_path(path) ⇒ Object

Loads a QML file from a file path.

See Also:



68
69
70
# File 'lib/qml/application.rb', line 68

def load_path(path)
  load(path: path)
end

#notify_error(error) ⇒ Object

Called when an Ruby error is occured in executing Qt code.

Parameters:

  • error

    The error (or the exception)



102
103
104
105
106
# File 'lib/qml/application.rb', line 102

def notify_error(error)
  warn "-- An error occured when running Ruby code from Qt --"
  warn "#{error.class.name}: #{error.message}"
  warn "Backtrace: \n\t#{error.backtrace.join("\n\t")}"
end

#process_eventsObject

Processes queued events in the event loop manually. This method is useful when you are combining an external event loop like EventMachine.



85
86
87
# File 'lib/qml/application.rb', line 85

def process_events
  @extension.process_events
end

#rootObject

Returns The root object created by the root component.

Returns:

  • The root object created by the root component.



73
74
75
# File 'lib/qml/application.rb', line 73

def root
  @root or fail "QML data or file has not been loaded"
end

#root_componentComponent

Returns The root component of the application that represents the loaded QML file.

Returns:

  • (Component)

    The root component of the application that represents the loaded QML file.

See Also:



46
47
48
# File 'lib/qml/application.rb', line 46

def root_component
  @root_component or fail ApplicationError, "QML data or file has not been loaded"
end