[Kde-bindings] qtruby: Qt::String uninit const

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Apr 14 08:37:55 UTC 2005


On Thursday 14 April 2005 09:34, jm wrote:
> I have the following in a class
>
> class Thing < Qt::Widget
>    ....
> def  paintEvent(e)
>      #s = Qt::String.new('aweeee') #Time.now.strftime('%H:%M'))
>      p = Qt::Painter.new(self)
>      0.upto(5) do |n|
>        p.drawText(50,50*n, ".")
>      end
>      s =   Qt::String.new(Time.now.strftime('%H:%M'))   #<--- line 45
>      p.drawText(250, 20, 50, 25, Qt::AlignRight, s)
>      p.drawLine(20, 50, 280, 50)
>      p.end
>    end
> ....
> end
>
> It doesn't seem to matter where I put Qt::String it gives me some thing
> like
>
> main.rb:45:in `const_missing': uninitialized constant Qt::String
> (NameError)
>          from main.rb:45:in `paintEvent'
>          from main.rb:90:in `method_missing'
>          from main.rb:90
>
> Most likely an obvious error I just can't see at the moment. Any
> suggestions?
Yes, you don't need to use Qt::String at all in QtRuby. Everywhere you see a 
QString parament in the C++ api you can use a ruby string and it will be 
automatically converted. Also the value of $KCODE is used to correctly 
convert to and from a unicode QString, according to the current ruby string 
format. 

This should work fine:

 class Thing < Qt::Widget
    ....
 def  paintEvent(e)
      #s = Qt::String.new('aweeee') #Time.now.strftime('%H:%M'))
      p = Qt::Painter.new(self)
      0.upto(5) do |n|
        p.drawText(50,50*n, ".")
      end
      s =   Time.now.strftime('%H:%M')  #<--- line 45
      p.drawText(250, 20, 50, 25, Qt::AlignRight, s)
      p.drawLine(20, 50, 280, 50)
      p.end
    end
 ....
 end

-- Richard



More information about the Kde-bindings mailing list