$KCODE = 'ut8'
require 'qte'
require 'qpe'
require 'sqlite3'
require 'kconv'
include Qte
include Qpe
class MyWindow < QMainWindow
def initialize
super
@lv = QListView.new(self)
self.setCentralWidget(@lv)
@lv.addColumn(tr('名前'), 200)
@lv.addColumn(tr('アドレス'), 200)
@new_flag = !File.exists?('test.db')
db = SQLite3::Database.new( "test.db" )
if(@new_flag) then
db.type_translation = true
sql = <<SQL
CREATE TABLE people (
id INTEGER PRIMARY KEY,
name TEXT,
address TEXT
);
SQL
db.execute(sql)
(1..100).each do |i|
sql = <<SQL
INSERT INTO people (name, address)
VALUES ('#{'名前'.toutf8 + sprintf("%03d",i.to_s)}',
'#{'アドレス'.toutf8}');
SQL
db.execute(sql)
end
end
sql = "SELECT * FROM people"
res = db.execute(sql)
res.each do |m|
QListViewItem.new(@lv, tr(m[1]),tr(m[2]))
end
db.close
end
end
class MyApp < QPEApplication
def initialize
super([$0]+ARGV)
self.setDefaultCodec(QTextCodec.codecForName('utf8'))
end
end
a = MyApp.new
mw = MyWindow.new
a.showMainWidget(mw)
a.exec