Bug 305515 - qtruby can't be used with QML, return type of QAbstractItemModel::roleNames is unrecognized
Summary: qtruby can't be used with QML, return type of QAbstractItemModel::roleNames i...
Status: RESOLVED WORKSFORME
Alias: None
Product: bindings
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR major
Target Milestone: ---
Assignee: kde-bindings
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-20 21:00 UTC by Florian Staudacher
Modified: 2022-11-18 05:16 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
add handlers for role name methods (64 bytes, patch)
2013-09-18 17:34 UTC, Florian Staudacher
Details
sorry, wrong file (3.64 KB, patch)
2013-09-18 17:39 UTC, Florian Staudacher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Staudacher 2012-08-20 21:00:25 UTC
Hi!
I already reported this issue to the kde-bindings mailing list [1] a while ago. 
Now I waited for KDE 4.9 to be released and re-pulled and re-built smokegen, smokeqt and qtruby from source, but I still cannot use an ItemModel written in QtRuby together with QML.

You can get more details by looking at my post to the mailing list

[1] http://lists.kde.org/?l=kde-bindings&m=134165976025397&w=2

Reproducible: Always

Steps to Reproduce:
run the following ruby snippet:

require 'Qt4'
model = Qt::AbstractListModel.new
model.role_names
Actual Results:  
this is the error message that is produced

classname    == QAbstractListModel
:: method == setRoleNames
-> methodIds == [#<Qt::Internal::ModuleIndex:0x00000002138970 @smoke=0, @index=282>]
candidate list:
        void QAbstractItemModel::setRoleNames(const QHash<int,QByteArray>&)  (smoke: 0 index: 282)
matching => smoke: 0 index: 282
      const QHash<int,QByteArray>& (U)
match => 282 score: 1
Resolved to id: 282
setCurrentMethod(smokeList index: 0, meth index: 282)
test.rb:282:in `method_missing': Cannot handle 'const QHash<int,QByteArray>&' as argument of QAbstractItemModel::setRoleNames (ArgumentError)

Expected Results:  
I should be able to use a model class from Ruby code with QML just like it always works with C++

$ kde4-config --version
Qt: 4.8.2
KDE: 4.9.00
kde4-config: 1.0

KDE and Qt are from Archlinux packages, 
smokegen, smokeqt and qtruby are compiled from git master
Comment 1 Florian Staudacher 2013-09-18 17:34:54 UTC
Created attachment 82394 [details]
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)
Comment 2 Florian Staudacher 2013-09-18 17:39:35 UTC
Created attachment 82395 [details]
sorry, wrong file
Comment 3 Justin Zobel 2022-10-19 22:10:58 UTC
Thank you for reporting this bug in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "CONFIRMED" when replying. Thank you!
Comment 4 Bug Janitor Service 2022-11-03 05:06:22 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 5 Bug Janitor Service 2022-11-18 05:16:38 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!