Bauduin Raphael
12/18/2004 1:31:00 PM
Hi,
Thanks for the tip about QProcess, I'll experiment with it later.
For the time being, I've implemented nobu nokada's suggestion.
I still have the problem refreshing the widget though....
With this code:
Thread.new("/tmp/test") do |f|
begin
tail = IO.popen("/usr/bin/tail -f #{f}","r")
while line = tail.gets
hello.append line.chomp
puts line.chomp
end
ensure
puts "killing #{tail.pid}"
Process.kill("INT", tail.pid)
tail.close
end
end
the while loops (updating the widget AND printing line in the terminal)
seems to be run only when activity occurs in the window (click, entering
window).
How comes the line is printed in the terminal only when activity occurs
in the window?
Thanks for your help
Raph
Richard Dale wrote:
> Richard Dale wrote:
>
>>You could start 'tail' with a Qt::Process instead of popen(), as it ties
>>in with Qt signals/slots
>
>
>>and shuts down the sub process on application
>>exit
>
> Actually I'm wrong - Qt doesn't do this, you need to connect to the
> 'aboutToQuit()' application signal, and kill the 'tail' process on exit:
>
> @proc = Qt::Process.new(self) {
> addArgument "/usr/bin/tail"
> addArgument "-f"
> addArgument "/tmp/test"
> }
>
> connect( @proc, SIGNAL('readyReadStdout()'),
> self, SLOT('readFromStdout()') )
>
> connect( $kapp, SIGNAL('aboutToQuit()'),
> self, SLOT('shutdown()') )
> @proc.start
> end
>
> slots 'readFromStdout()', 'shutdown()'
>
> def readFromStdout
> lines = @proc.readStdout
> @hello.append lines.to_s
> end
>
> def shutdown
> @proc.kill
> end
>
> -- Richard