Fragment of code what I tried to execute. I'm newbie in ruby development, so if it's only my gaps in knowledge, keep me informing ;)
It's what I try to execute
`class Dices < Qt::Dialog
def initialize
super
setWindowTitle "Warhammer - Dices"
dices
resize 500, 300
move 300, 500
show
end
def dices
vbox = Qt::VBoxLayout.new
hbox1 = Qt::HBoxLayout.new
hbox2 = Qt::HBoxLayout.new
vbox1 = Qt::VBoxLayout.new
vbox2 = Qt::VBoxLayout.new
vbox3 = Qt::VBoxLayout.new
vbox4 = Qt::VBoxLayout.new
vbox5 = Qt::VBoxLayout.new
dk4 = Qt::PushButton.new("Dice k4")
@dk4edit = Qt::LineEdit.new
dk6 = Qt::PushButton.new("Dice k6")
@dk6edit = Qt::LineEdit.new
dk8 = Qt::PushButton.new("Dice k8")
@dk8edit = Qt::LineEdit.new
dk10 = Qt::PushButton.new("Dice k10")
@dk10edit = Qt::LineEdit.new
dk100 = Qt::PushButton.new("Dice k100")
@dk100edit = Qt::LineEdit.new
@resultlog = Qt::TextEdit.new
#puts methtest.methods
def rollk4
x = @dk4edit.displayText
Thread.new{
begin
if x == ""
x = "1"
elsif x.to_i > 10
x = 10
end
r4 = []
x.to_i.times do
d4 = Random.new
r4 << d4.rand(1 .. 4)
end
r4.each do |line|
t = Time.new
Qt.execute_in_main_thread{@resultlog.append "Result K4: #{line} - #{t}"}
end
r4.clear
rescue
puts "Something is not good"
end
}
end
def rollk6
x = @dk6edit.displayText
Thread.new{
begin
if x == ""
x = "1"
elsif x.to_i > 10
x = 10
end
r6 = []
x.to_i.times do
d6 = Random.new
r6 << d6.rand(1 .. 6)
end
r6.each do |line|
t = Time.new
Qt.execute_in_main_thread{@resultlog.append "Result K6: #{line} - #{t}"}
end
r6.clear
rescue
puts "Something is not good"
end
}
end
def rollk8
x = @dk8edit.displayText
Thread.new{
begin
if x == ""
x = "1"
elsif x.to_i > 10
x = 10
end
r8 = []
x.to_i.times do
d8 = Random.new
r8 << d8.rand(1 .. 8)
end
r8.each do |line|
t = Time.new
Qt.execute_in_main_thread{@resultlog.append "Result K8: #{line} - #{t}"}
end
r8.clear
rescue
puts "Something is not good"
end
}
end
def rollk10
x = @dk10edit.displayText
Thread.new{
begin
if x == ""
x = "1"
elsif x.to_i > 10
x = 10
end
r10 = []
x.to_i.times do
d10 = Random.new
r10 << d10.rand(1 .. 10)
end
r10.each do |line|
t = Time.new
Qt.execute_in_main_thread{@resultlog.append "Result K10: #{line} - #{t}"}
end
r10.clear
rescue
puts "Something is not good"
end
}
end
def rollk100
x = @dk100edit.displayText
Thread.new{
begin
if x == ""
x = "1"
elsif x.to_i > 10
x = 10
end
r100 = []
x.to_i.times do
d100 = Random.new
r100 << d100.rand(1 .. 100)
end
r100.each do |line|
t = Time.new
Qt.execute_in_main_thread{@resultlog.append "Result K100: #{line} - #{t}"}
end
r100.clear
rescue
puts "Something is not good"
end
}
end
dk4.connect( SIGNAL( :clicked )) do
rollk4
end
dk6.connect( SIGNAL( :clicked )) do
rollk6
end
dk8.connect( SIGNAL( :clicked )) do
rollk8
end
dk10.connect( SIGNAL( :clicked )) do
rollk10
end
dk100.connect( SIGNAL( :clicked )) do
rollk100
end
vbox.addLayout hbox1
vbox.addLayout hbox2
hbox1.addLayout vbox1
hbox1.addLayout vbox2
hbox1.addLayout vbox3
hbox1.addLayout vbox4
hbox1.addLayout vbox5
hbox2.addWidget @resultlog
vbox1.addWidget dk4
vbox1.addWidget @dk4edit, Qt::AlignTop
vbox2.addWidget dk6
vbox2.addWidget @dk6edit, Qt::AlignTop
vbox3.addWidget dk8
vbox3.addWidget @dk8edit, Qt::AlignTop
vbox4.addWidget dk10
vbox4.addWidget @dk10edit, Qt::AlignTop
vbox5.addWidget dk100
vbox5.addWidget @dk100edit, Qt::AlignTop
setLayout vbox
end
end`
And that class is execute from menu simple menu like
`
class Menu < Qt::Widget
def initialize
super
init_ui
resize 230, 70
move 300, 300
show
end
def init_ui
vbox = Qt::VBoxLayout.new
dices = Qt::PushButton.new
dices.connect(SIGNAL(:clicked)) do
Dices.new
end
vbox.addWidget dices
setLayout vbox
end
end
class Main < Qt::MainWindow
def initialize
super
setWindowTitle "Warhammer - Player Panel"
setCentralWidget Menu.new
show
end
end
app = Qt::Application.new ARGV
Main.new
app.exec
`
To reproduce it:
Run it script (It's not exactly my app, but you can also get error from that)
Click multiple times on Pushbutton in Dices class
run some other soft like webbrowser
click on the web browser and back to app
repeat until you get error
And, other problem, If i try change window, sometimes I can't interact with object in child window(like Dices)
I cannot recreate the crash. When threading it is very important to make sure that all GUI objects still exist at the time the thread is running. That might be the problem.
Hello, i get that output when I try to execute my script...
Fragment of code what I tried to execute. I'm newbie in ruby development, so if it's only my gaps in knowledge, keep me informing ;)
It's what I try to execute
`class Dices < Qt::Dialog
end`
And that class is execute from menu simple menu like
To reproduce it:
And, other problem, If i try change window, sometimes I can't interact with object in child window(like Dices)
Thanks for help and Regards
:)