Bauduin Raphael wrote: > Hi, > > I'm looking at Qtruby, trying to write a little log view app. > I'm basing the app on the p3 app from the tutorial found here: > http://developer.kde.org/language-bindings/ruby/kde3tutorial/p3.html > > I modify it like that: > > hello = Qt::TextEdit.new( "", "", self) > hello.textFormat = Qt::LogText > > setCentralWidget hello > > Thread.new("/tmp/test") do |f| > tail = IO.popen("/usr/bin/tail -f #{f}","r") > > while line = tail.gets > hello.append line.chomp > #hello.refresh > end > end > > > First problem: when I qui the app, the tail -f continues to run. > I also tried to put the while in a block passed to IO.popen, with the > same result. This then understandably results in the message > > /usr/bin/tail: write error: Broken pipe > /usr/bin/tail: write error > > in the terminal from which I started the app when a new line is appended > to the watched file. > > I have also problems refreshing the widget when a new log line is > appended. If I uncomment hello.refresh after hello.append, only the > first line is displayed in the widget when I start the app, and when new > log lines are appended to the watched file, I get the broken pipe in the > terminal. When replacing hello.refresh by puts line.chomp, the program > works fine, except for the refrech problem..... 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: @hello = Qt::TextEdit.new("", "", self) @hello.textFormat = Qt::LogText setCentralWidget(@hello) @proc = Qt::Process.new(self) { addArgument "/usr/bin/tail" addArgument "-f" addArgument "/tmp/test" } connect( @proc, SIGNAL('readyReadStdout()'), self, SLOT('readFromStdout()') ) @proc.start end slots 'readFromStdout()' def readFromStdout lines = @proc.readStdout @hello.append lines.to_s end -- Richard