Class: QML::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/qml/component.rb

Overview

The Component class is used to instantiate objects like Window / ApplicationWindow objects from QML files.

You usually do not need to use this class because Application#load, #load_path, #load_data do same for the application top-level objects such as main windows.

Examples:

component = Component.new(engine: engine, path: path_to_qml_file)
root_object = component.create

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data: nil, path: nil) ⇒ Object

Creates an component. Either data or path must be specified.

Parameters:

  • data (String) (defaults to: nil)

    the QML file data.

  • path (#to_s) (defaults to: nil)

    the QML file path.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qml/component.rb', line 19

def initialize(data: nil, path: nil)
  fail TypeError, "neither data nor path privided" unless data || path

  initialize_impl

  case
  when data
    load_data(data)
  when path
    load_path(path)
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#createQML::JSObject

Instantiates a object from the QML file.

Returns:



51
52
53
54
55
# File 'lib/qml/component.rb', line 51

def create
  check_error_string do
    create_impl
  end
end

#load_data(data) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/qml/component.rb', line 41

def load_data(data)
  check_error_string do
    @data = data
    load_data_impl(data, "<<STRING>>")
  end
  self
end

#load_path(path) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/qml/component.rb', line 32

def load_path(path)
  path = path.to_s
  check_error_string do
    @path = Pathname.new(path)
    load_path_impl(path)
  end
  self
end