Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Nico Forlano
RE: Qt::Variant and Qt::Alignment constants [ reply ]  
2010-10-27 13:15
I see, thanks.

By: Jan Pilz
RE: Qt::Variant and Qt::Alignment constants [ reply ]  
2010-10-27 12:59
Hi,

when you look at Qt Documentation, you'll see that QVariant does not support QEnum:

irb(main):002:0> require 'Qt4'
=> true
irb(main):003:0> Qt::Variant.new(Qt::AlignRight)
ArgumentError: unresolved constructor call

-> you see there is no construnctor for an QEnum

irb(main):018:0> Qt::Variant.new(Qt::AlignRight.to_i).value == Qt::AlignRight
=> true

-> this works

By: Nico Forlano
Qt::Variant and Qt::Alignment constants [ reply ]  
2010-10-10 16:19
Hi,

I have a problem using the Qt::Variant in a Model/View function QAbstractItemModel::data(index, role).
Just wanted to point out the behaviour, not sure if I should report this as a bug.
In case of a Qt::TextAlignmentRole using Qt::Variant.new(Qt::AlignRight) causes a crash.

irb(main):001:0> require 'Qt'
=> true
irb(main):002:0> Qt::Variant.new(Qt::AlignRight)
NoMethodError: undefined method `index' for nil:NilClass
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2715:in `isConstMethod'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2715:in `do_method_missing'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2698:in `each'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2698:in `do_method_missing'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2207:in `initialize'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2207:in `initialize'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2611:in `call'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2611:in `try_initialize'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2610:in `catch'
from C:/Ruby/ruby_1.8.6-p398/lib/ruby/gems/1.8/gems/qtruby4-2.1.0-x86-mswin32/lib/Qt/qtruby4.rb:2610:in `try_initialize'
from (irb):2:in `new'
from (irb):2
from :0
irb(main):003:0> Qt::AlignRight
=> 2
irb(main):004:0> Qt::AlignRight.class
=> Qt::Enum
irb(main):005:0> Qt::Variant.new(2)
=> #<Qt::Variant:0x33ff918 typeName=int>

Qt::Variant.new(2) works fine.

Best regards