[Kde-bindings] qtruby: Qt::TextView issue?
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Tue Sep 21 09:26:37 UTC 2004
On Tuesday 21 September 2004 04:12, Arash Abedinzadeh wrote:
> Hi,
>
> I noticed a weird behavior of qtruby and Qt::TextView respectively. I wrote
> a small script (attached), which starts a connection to an IRC server,
> reads everything that comes into the socket and adds the received strings
> to the Qt::TextView object. The problem is that somehow the widget needs
> some kind of signal, like a resize event, a mouseclick or something like
> that to draw the new strings.
>
> But actually I'm not even sure whether it's a qtruby issue or if messed up
> something in my code. Could someone please take a look at it? Thanks.
I think the problem is that you can't mix ruby threads with Qt apps. Instead
you could use a Qt::Timer to poll the socket every 200 ms or so like this
code below.
-- Richard
class Client < Qt::Object
slots 'input()'
private
def initialize(cfg, gui)
super()
@cfg = cfg
@gui = gui
@socket = TCPSocket.new(cfg[:server], cfg[:port])
login
@timer = Qt::Timer.new
connect(@timer, SIGNAL('timeout()'), SLOT('input()'))
@timer.start(200)
end
def send(str, flags = 0)
@socket.send("#{str}\r\n", flags)
end
def gets
@socket.gets("\r\n")
end
def login
send("NICK #{@cfg[:nick]}")
send("PASS #{@cfg[:pass]}") if @cfg[:pass]
send("USER #{@cfg[:username]} #{@cfg[:hostname]} #{@cfg[:servername]}
#{@cfg[:realname]}")
end
public
def input
io = select([@socket], nil, nil, nil)
if io
@gui.out(gets)
end
end
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qtirc.rb
Type: application/x-ruby
Size: 1286 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20040921/6fc4ef64/attachment-0001.bin>
More information about the Kde-bindings
mailing list