Class: QML::Application
- Inherits:
-
QtObjectBase
- Object
- QtObjectBase
- QML::Application
- 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.
Instance Attribute Summary
Attributes inherited from QtObjectBase
Class Method Summary collapse
-
.instance ⇒ Application
The application instance.
- .new ⇒ Object
- .notify_error(error) ⇒ Object
Instance Method Summary collapse
-
#collect_garbage ⇒ Object
Runs garbage collection of Ruby and QML and deletes unused objects.
-
#context ⇒ Context
The root context of the engine.
-
#engine ⇒ Engine
The engine of the application.
-
#exec ⇒ Object
Starts the event loop of the application.
- #force_deferred_deletes ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#load(opts) ⇒ Object
Loads a QML file.
-
#load_data(data) ⇒ Object
Loads a QML file from string data.
-
#load_path(path) ⇒ Object
Loads a QML file from a file path.
-
#notify_error(error) ⇒ Object
Called when an Ruby error is occured in executing Qt code.
-
#process_events ⇒ Object
Processes queued events in the event loop manually.
-
#root ⇒ Object
The root object created by the root component.
-
#root_component ⇒ Component
The root component of the application that represents the loaded QML file.
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
Constructor Details
#initialize ⇒ Application
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
.instance ⇒ Application
Returns The application instance.
13 14 15 |
# File 'lib/qml/application.rb', line 13 def self.instance Kernel.application end |
.new ⇒ Object
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_garbage ⇒ Object
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 |
#context ⇒ Context
Returns The root context of the engine.
38 39 40 |
# File 'lib/qml/application.rb', line 38 def context engine.context end |
#engine ⇒ Engine
Returns The engine of the application.
32 33 34 |
# File 'lib/qml/application.rb', line 32 def engine Kernel.engine end |
#exec ⇒ Object
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_deletes ⇒ Object
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
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.
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.
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.
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.}" warn "Backtrace: \n\t#{error.backtrace.join("\n\t")}" end |
#process_events ⇒ Object
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 |
#root ⇒ Object
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_component ⇒ Component
Returns The root component of the application that represents the loaded QML file.
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 |