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

Defined Under Namespace

Classes: SubclassBuilder

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.



167
168
169
# File 'lib/qml/qt_object_base.rb', line 167

def meta_object
  @meta_object
end

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



171
172
173
# File 'lib/qml/qt_object_base.rb', line 171

def pointer
  @pointer
end

Instance Method Details

#inspectObject Also known as: to_s



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/qml/qt_object_base.rb', line 194

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)


221
222
223
# File 'lib/qml/qt_object_base.rb', line 221

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.



214
215
216
# File 'lib/qml/qt_object_base.rb', line 214

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)


229
230
231
# File 'lib/qml/qt_object_base.rb', line 229

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: <<-EOS
  import QtQuick 2.0
  QtObject {
    property string foo: 'foo'
    property string bar: 'bar'
  }
EOS
obj = component.create
obj.qml_eval("foo + bar") #=> "foobar"

Parameters:

  • str (String)

Returns:

  • the result.



188
189
190
191
192
# File 'lib/qml/qt_object_base.rb', line 188

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