[Kde-bindings] QtRuby: segfault when using Qt::ForegroundRole
Legolgo
legolgo at laposte.net
Mon Jul 26 14:04:11 UTC 2010
Le 26/07/2010 21:14, Richard Dale a écrit :
> On Monday, July 26, 2010 09:11:48 am Legolgo wrote:
>
>> Hi everyone,
>>
>> I started using qtruby a few days ago and so far it's been great.
>> But I stumbled upon a bug that causes a segfault.
>>
>> As I just started using Qt and the qtruby binding I don't know if I'm
>> doing something wrong with my custom model or if it's a bug of the binding.
>>
>> Here is some minimal code that reproduce the error:
>>
>> require "Qt4"
>>
>> class TaskListModel< Qt::StandardItemModel
>>
>> def initialize(parent = nil)
>> super(parent)
>> end
>>
>> def data(index, role)
>> if !index.valid?
>> return Qt::Variant.new
>> end
>> if role == Qt::DisplayRole
>> item = item(index.row)
>> return Qt::Variant.new(item.text)
>> end
>> #this role cause a segfault, sometimes you have to wait a
>> little bit or try to edit rows
>> if role == Qt::ForegroundRole
>> return Qt::Brush.new()
>> end
>>
>> return Qt::Variant.new
>>
>> end
>>
>>
>> end
>>
>> app = Qt::Application.new(ARGV)
>> @widget = Qt::ListView.new()
>>
>> @model = TaskListModel.new
>> @widget.setModel(@model)
>> #fill model with some data
>> ["toto", "tata", "tutu"].each do |desc|
>> item = Qt::StandardItem.new
>> item.text = desc
>> @model.appendRow(item)
>> end
>>
>> @widget.show()
>> app.exec()
>>
>> I'm using the libQt4-ruby from ubuntu 10.04 with ruby 1.8
>>
> This 'return Qt::Brush.new()' looks wrong to me - I think you need to return a
> Qt::Brush inside a Qt::Variant with Qt::Variant.fromValue(Qt::Brush.new()).
>
> -- Richard
>
Thanks, you were right, no more segfault with:
Qt::Variant.fromValue(Qt::Brush.new())
So it means that when the type you want to return is not directly
supported by Qt::Variant, you have to use Qt::Variant.fromValue.
Thank you again,
Florian
More information about the Kde-bindings
mailing list