Class: QML::QtObjectBase

Inherits:
Object
  • Object
show all
Includes:
Dispatchable, Reactive::Object
Defined in:
lib/qml/qt_object_base.rb

Overview

QtObjectBase is the base class for Qt object wrappers.

In ruby-qml you can access the followings of Qt objects in Ruby.

Properties and signals support is provided by Reactive::Object.

While their names are camelCase in Qt, ruby-qml aliases them as underscore_case.

Examples:

# QML::Application is actually a wrapper for QApplication
app = QML.application

# set property
app.applicationName = "Test"
app.application_name = "Test" # aliased version

# connect to signal
app.aboutToQuit.connect do # "about_to_quit" is also OK
  puts "quitting..."
end

# call slot
app.quit

Direct Known Subclasses

Application, Component, Context, Engine, Qt

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reactive::Object

included, #initialize, #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

Class Attribute Details

.meta_objectObject

Returns the value of attribute meta_object.



37
38
39
# File 'lib/qml/qt_object_base.rb', line 37

def meta_object
  @meta_object
end

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



41
42
43
# File 'lib/qml/qt_object_base.rb', line 41

def pointer
  @pointer
end

Instance Method Details

#custom_dataObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/qml/qt_object_base.rb', line 45

def custom_data
  @custom_data ||= {}
end

#inspectObject Also known as: to_s



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/qml/qt_object_base.rb', line 69

def inspect
  klass = self.class
  property_inspect = klass.instance_properties.sort
    .reject { |name| klass.instance_property(name).alias? }
    .map do |name|
      "#{name}=" +
        begin
          property(name).value.inspect
        rescue ConversionError
          "<unsupported type>"
        end
    end
    .join(' ')
  classname = klass.name || "[class for #{klass.meta_object.name}]"
  "#<#{classname}:#{__id__} #{property_inspect}>"
end

#managed=(managed) ⇒ Boolean

Sets the management status of the object.

Parameters:

  • managed (Boolean)

Returns:

  • (Boolean)


96
97
98
# File 'lib/qml/qt_object_base.rb', line 96

def managed=(managed)
  pointer.managed = managed
end

#managed?Boolean

Returns whether the object is managed by Ruby and QML and garbage collected when no longer used.

Returns:

  • (Boolean)

    whether the object is managed by Ruby and QML and garbage collected when no longer used.



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

def managed?
  pointer.managed?
end

#prefer_managed(managed) ⇒ Boolean

Sets the management status of the object in safer way. Objects that are created by QML will remain managed and objects that have parents will remain unmanaged.

Parameters:

  • managed (Boolean)

Returns:

  • (Boolean)


104
105
106
# File 'lib/qml/qt_object_base.rb', line 104

def prefer_managed(managed)
  pointer.prefer_managed managed
end

#qml_eval(str) ⇒ Object

Evaluates a JavaScript expression on the QML context of the object. Fails with QML::QMLError when the object is not created by QML and does not belong to any context.

Examples:

component = QML::Component.new data: "  import QtQuick 2.0\n  QtObject {\n    property string foo: 'foo'\n    property string bar: 'bar'\n  }\n"
obj = component.create
obj.qml_eval("foo + bar") #=> "foobar"

Parameters:

  • str (String)

Returns:

  • the result.



63
64
65
66
67
# File 'lib/qml/qt_object_base.rb', line 63

def qml_eval(str)
  context = Context.for_object(self)
  fail QMLError, 'belongs to no context' unless context
  context.eval(self, str)
end