[Kde-bindings] [bindings] [Bug 305515] qtruby can't be used with QML, return type of QAbstractItemModel::roleNames is unrecognized

Florian Staudacher florian_staudacher at yahoo.de
Wed Sep 18 17:34:54 UTC 2013


https://bugs.kde.org/show_bug.cgi?id=305515

--- Comment #1 from Florian Staudacher <florian_staudacher at yahoo.de> ---
Created attachment 82394
  --> https://bugs.kde.org/attachment.cgi?id=82394&action=edit
add handlers for role name methods

here is a patch that fixes that problem for me (not sure if the code should be
ifdefed to a minimum version of Qt)...
with this models written in ruby can have role names set.

# example: subclassing a QListModel
class TestModel < Qt::ListModel
  def initialize
    super
    set_role_names({ 1000 => "user_role", 1001 => "another_role"})
  end

  def rowCount(parent)
    x
  end

  # yes, it's a list, but for some reason it needs this method 
  # to be implemented. just humor me here...
  def columnCount(parent)
    1
  end

  def data(idx, role)
    return Qt::Variant.new("something") if role == 1000
    return Qt::Variant.new("otherthing") if role == 1001
  end
end

and then it can be attached the model to the root context of a
QDeclarativeView.
this allows it to be used via qml like any other C++ model.

@model = TestModel.new
@qmlview = Qt::DeclarativeView.new
@ctx = @qmlview.root_context
@ctx.set_context_property("test_model", @model)

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Kde-bindings mailing list