<HTML dir=ltr><HEAD><TITLE>Re: [Kde-bindings] QT TextEdit refresh</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16481" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText46433 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Richard,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Thanks for the prompt reply - that did the trick.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Just need to try and find a good place where this sort of stuff is documented! </FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>I've seen the pragmatic Ruby QT book, but that's QT 3 based a seems a bit on the light side. </FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Can you recommend anything publications that's QT/Ruby specific? Don't fancy trying to learn C++.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Best Regards,</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Carl</FONT></DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Richard Dale [mailto:rdale@foton.es]<BR><B>Sent:</B> Tue 24/07/2007 17:48<BR><B>To:</B> KDE bindings for other programming languages<BR><B>Subject:</B> Re: [Kde-bindings] QT TextEdit refresh<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>On Tuesday 24 July 2007, Carl Bourne wrote:</FONT> <BR><FONT size=2>> require 'Qt'</FONT> <BR><FONT size=2>> require 'dialog.rb'</FONT> <BR><FONT size=2>> app = Qt::Application.new(ARGV)</FONT> <BR><FONT size=2>> dialog = Dialog.new</FONT> <BR><FONT size=2>> dialog.exec</FONT> <BR><FONT size=2>>  </FONT> <BR><FONT size=2>> ------</FONT> <BR><FONT size=2>> dialog.rb</FONT> <BR><FONT size=2>> -------</FONT> <BR><FONT size=2>>  </FONT> <BR><FONT size=2>> class MyWidget < Qt::Widget</FONT> <BR><FONT size=2>>   slots 'go()'</FONT> <BR><FONT size=2>>   def initialize(parent = nil)</FONT> <BR><FONT size=2>>     super(parent)</FONT> <BR><FONT size=2>>     setFixedSize(500, 500)</FONT> <BR><FONT size=2>>     @textedit = Qt::TextEdit.new(self)</FONT> <BR><FONT size=2>>     @textedit.setGeometry(5, 50, 480, 300)</FONT> <BR><FONT size=2>>  </FONT> <BR><FONT size=2>>     quit = Qt::PushButton.new(('Generate'), self)</FONT> <BR><FONT size=2>>     quit.setGeometry(5, 5, 100, 30)</FONT> <BR><FONT size=2>>     quit.setFont(Qt::Font.new('Arial', 12, Qt::Font::Bold))</FONT> <BR><FONT size=2>>     connect(quit, SIGNAL(:clicked)) {@textedit.clear();  go() }</FONT> <BR><FONT size=2>>   end</FONT> <BR><FONT size=2>>    </FONT> <BR><FONT size=2>>   def go</FONT> <BR><FONT size=2>>       #   @textedit.clear()</FONT> <BR><FONT size=2>>       @textedit.setText("Generating files:-")</FONT> <BR><FONT size=2>>       count = 0</FONT> <BR><FONT size=2>>       50.times do</FONT> <BR><FONT size=2>>         count+=1</FONT> <BR><FONT size=2>>         sleep 0.1</FONT> <BR><FONT size=2>>         @textedit.append("Generating file: "+count.to_s)    </FONT> <BR><FONT size=2>>         puts "hello"</FONT> <BR><FONT size=2>>       end</FONT> <BR><FONT size=2>>       @textedit.append("Done")</FONT> <BR><FONT size=2>>   end</FONT> <BR><FONT size=2>> end</FONT> <BR><FONT size=2>> app = Qt::Application.new(ARGV)</FONT> <BR><FONT size=2>> widget = MyWidget.new()</FONT> <BR><FONT size=2>> widget.show()</FONT> <BR><FONT size=2>> app.exec()</FONT> <BR><FONT size=2>The Qt::TextEdit won't get repainted until you return to the event loop. So if </FONT><BR><FONT size=2>you do everything inside to go() method you won't return to the event loop </FONT><BR><FONT size=2>until you've done the 50 iterations.</FONT> </P>
<P><FONT size=2>You need to do the 'Generating files' processing in another method, that is </FONT><BR><FONT size=2>called once before control returns to the event loop like this for instance:</FONT> </P>
<P><FONT size=2>class MyWidget < Qt::Widget</FONT> <BR><FONT size=2>  slots :go, :generate</FONT> <BR><FONT size=2>  def initialize(parent = nil)</FONT> <BR><FONT size=2>    super(parent)</FONT> <BR><FONT size=2>    setFixedSize(500, 500)</FONT> <BR><FONT size=2>    @textedit = Qt::TextEdit.new(self)</FONT> <BR><FONT size=2>    @textedit.setGeometry(5, 50, 480, 300)</FONT> </P>
<P><FONT size=2>    quit = Qt::PushButton.new(('Generate'), self)</FONT> <BR><FONT size=2>    quit.setGeometry(5, 5, 100, 30)</FONT> <BR><FONT size=2>    quit.font = Qt::Font.new('Arial', 12, Qt::Font::Bold)</FONT> <BR><FONT size=2>    connect(quit, SIGNAL(:clicked)) {@textedit.clear(); go() }</FONT> <BR><FONT size=2>  end</FONT> <BR><FONT size=2>  </FONT><BR><FONT size=2>  def go</FONT> <BR><FONT size=2>      #   @textedit.clear()</FONT> <BR><FONT size=2>      @textedit.text = "Generating files:-"</FONT> <BR><FONT size=2>      @count = 0</FONT> <BR><FONT size=2>      generate</FONT> <BR><FONT size=2>  end</FONT> </P>
<P><FONT size=2>  def generate</FONT> <BR><FONT size=2>     @count += 1</FONT> <BR><FONT size=2>     @textedit.append("Generating file: "+@count.to_s)   </FONT><BR><FONT size=2>     puts "hello"</FONT> <BR><FONT size=2>     if @count == 50</FONT> <BR><FONT size=2>       @textedit.append("Done")</FONT> <BR><FONT size=2>     else</FONT> <BR><FONT size=2>       @timer = Qt::Timer.singleShot(100, self, SLOT(:generate))</FONT> <BR><FONT size=2>     end</FONT> <BR><FONT size=2>  end</FONT> <BR><FONT size=2>end</FONT> </P><BR>
<P><FONT size=2>PS: The two pieces of your code didn't seem to quite match as there was no </FONT><BR><FONT size=2>Dialog class in dialog.rb..</FONT> </P>
<P><FONT size=2>-- Richard</FONT> </P>
<P><FONT size=2>_______________________________________________</FONT> <BR><FONT size=2>Kde-bindings mailing list</FONT> <BR><FONT size=2>Kde-bindings@kde.org</FONT> <BR><FONT size=2><A href="https://mail.kde.org/mailman/listinfo/kde-bindings">https://mail.kde.org/mailman/listinfo/kde-bindings</A></FONT> <BR><BR><FONT size=2>No virus found in this incoming message.<BR>Checked by AVG Free Edition.<BR>Version: 7.5.476 / Virus Database: 269.10.16/914 - Release Date: 23/07/2007 19:45<BR></FONT>  </P></DIV></BODY></HTML>