#!/usr/bin/env ruby require "qte" require "qpe" require "thread" include Qte include Qpe class SampleWindow < QMainWindow def initialize() super() setCaption(tr("サンプル")) @msg = QLabel.new(tr("これはサンプルプログラム"),self) @msg.setGeometry(10,10,300,30) @ebox1 = QMultiLineEdit.new(self) @ebox1.setGeometry(0,100,635,300) @ebox1.setReadOnly(true) @pb1 = QPushButton.new(tr("ボタン1"),self) @pb1.setGeometry(300,5,100,30) connect(@pb1,QSIGNAL("clicked()"), self, 'cnt') # @a = Mutex.new @x = 100 @y = 100 @z = nil end def cnt @ebox1.clear @x = 100 @y = 100 Thread.new do Thread.pass 100.times do |i| # @a.synchronize { @x = @x + 1 sleep 0.1 @y = @y - 1 # } end end 100.times do # @a.synchronize { @z = @x + @y # } @ebox1.insertLine(@z.to_s) if @z != 200 then @ebox1.insertLine("!!!Error!!!") end end end end $defaultCodec = QTextCodec.codecForName("utf8") app = QPEApplication.new([$0]+ARGV) app.setDefaultCodec($defaultCodec) QApplication.setFont(QFont.new("lcfont",18)) app.showMainWidget(SampleWindow.new) app.exec