エミットを使用して GUI のステータスを更新すると、アプリがフリーズします。
このフリーズを回避する理由または回避方法を知りたいです。レビューありがとうございます。
私のテスト環境
- ウィンドウズ 7 x64
- railsinstaller-3.0.0.exe(MD5 : 26889DE0029C01A45AD2AED873708057)
- qtbindings (4.8.5.2 x86-mingw32)
- qtbindings-qt (4.8.5 x86-mingw32)
デモアプリは以下にあります。
#!/usr/bin/env ruby
# encoding: UTF-8
#
require 'Qt'
class App < Qt::MainWindow
signals 'test()'
slots 'on_test()'
def initialize
super
@label = Qt::Label.new
self.centralWidget = @label
self.show
connect self, SIGNAL('test()'), SLOT('on_test()')
start_count
end
def start_count
Thread.new do
loop {
emit test()
}
end
end
def on_test()
@label.text = @label.text.to_i + 1
end
end
app = Qt::Application.new(ARGV)
App.new
app.exec
@hyde ご回答ありがとうございます。
qtbindings の解決策 2 は役に立たないようです。
connect self, SIGNAL('test()'), SLOT('on_test()')
=>
connect self, SIGNAL('test()'), SLOT('on_test()'), Qt::BlockingQueuedConnection
ソリューション 1 がテストされ、アプリは問題なく動作します。
ソリューション 1 のコード:
#!/usr/bin/env ruby
# encoding: UTF-8
#
require 'Qt'
class App < Qt::MainWindow
slots 'on_test()'
def initialize
super
@label = Qt::Label.new
self.centralWidget = @label
self.show
@c = Qt::AtomicInt.new
start_count
start_timer
end
def start_count
Thread.new do
loop {
@c.fetchAndAddRelaxed(1)
}
end
end
def start_timer
t = Qt::Timer.new(self)
t.start(16)
connect t, SIGNAL('timeout()'), SLOT('on_test()')
end
def on_test()
@label.text = @c.fetchAndAddRelaxed(0) + 1
end
end
app = Qt::Application.new(ARGV)
App.new
app.exec