G
gregarican
I have an app that I wrote using Ruby-Qt2. The main application is
fine, but I want to add something to it. I want a listener thread that
waits for incoming signals. The thread would need to operate as a loop.
For my example I just made a basic closed iterator to test things out.
Here is a sample:
-----------------
require "qt2"
include Qt2
require "applicationWindow" # a derived Qt class I made
listener=Thread.new {
puts "this is a sample of my listener thread!\n"
10.times do |i|
sleep 1
puts "#{i} second(s)...\n"
end
}
qtApp = Thread.new {
a = QApplication.new([$0]+ARGV)
mw = ApplicationWindow.new
mw.setCaption( QString.new("Qt App") )
mw.show
a.exec
}
listener.join
qtApp.join
------------------
The problem is that the threads don't seem to work independently. The
listener thread won't advance until the Qt application has processed a
couple of events. So the seconds don't count up in real-time. This
takes place on a Win32 platform, so I don't think I can use a fork
method to split things off independently.
Any suggestions on how my listening thread can work independently on my
Win32 platform? I have read about the QThread object, but am not sure
that this is the way to go...
fine, but I want to add something to it. I want a listener thread that
waits for incoming signals. The thread would need to operate as a loop.
For my example I just made a basic closed iterator to test things out.
Here is a sample:
-----------------
require "qt2"
include Qt2
require "applicationWindow" # a derived Qt class I made
listener=Thread.new {
puts "this is a sample of my listener thread!\n"
10.times do |i|
sleep 1
puts "#{i} second(s)...\n"
end
}
qtApp = Thread.new {
a = QApplication.new([$0]+ARGV)
mw = ApplicationWindow.new
mw.setCaption( QString.new("Qt App") )
mw.show
a.exec
}
listener.join
qtApp.join
------------------
The problem is that the threads don't seem to work independently. The
listener thread won't advance until the Qt application has processed a
couple of events. So the seconds don't count up in real-time. This
takes place on a Win32 platform, so I don't think I can use a fork
method to split things off independently.
Any suggestions on how my listening thread can work independently on my
Win32 platform? I have read about the QThread object, but am not sure
that this is the way to go...