我正在尝试将msg
var 从show
User_Info 类中的show
方法传递给 Call_Win 类中的方法。我被卡住了rubyv2/call_win.rb:4:in initialize: unresolved constructor call Call_Win (ArgumentError)
。
主文件
require "Qt"
require "unirest"
require "redis"
class QtApp < Qt::Widget
require_relative "user_info"
slots "login()"
def initialize
super
setWindowTitle "Login"
init_ui
resize 400, 90
move 0, 0
show
end
def init_ui
@show = Qt::PushButton.new "Login", self
connect(@show, SIGNAL("clicked()"),
self, SLOT("login()"))
@show.move 20, 20
@username = Qt::LineEdit.new self
@username.move 130, 20
@username.setText "remy@gmail.com"
@password = Qt::LineEdit.new self
@password.setEchoMode(2)
@password.move 130, 50
@password.setText "remy@gmail.com"
end
def login
button = sender
if "Login" == button.text
call()
elsif "Logout" == button.text
logout()
end
end
def logout
@app.quit
end
def call
response = Unirest::post("http://localhost:3000/user_token",
headers:{
"content_type" => "application/json"
},
parameters:{auth: [{
:email => "#{@username.text}",
:password => "#{@password.text}"
}]}
)
$global_variable = "#{response.body["jwt"]}"
puts "#{response.code} #{@username.text} #{@password.text}"
if response.code == 201
@show.setText "Logout"
Qt::MessageBox.information self, "#{$global_variable}", " Logged In ;) [#{response.body["jwt"]}]"
User_Info.new
elsif response.code == 404
Qt::MessageBox.warning self, "#{@username.text}", "Unkown User"
end
end
end
@app = Qt::Application.new ARGV
QtApp.new
@app.exec
User_Info 类
class User_Info < Qt::Widget
require_relative 'call_win'
def initialize
super
setWindowTitle "Menu"
init_ui
resize 400, 600
move 401, 0
show
end
def init_ui
$redis = Redis.new(host: "192.168.43.1", port: 6379)
show()
end
def show()
$redis.subscribe('ruby') do |on|
on.message do |channel, msg|
Call_Win.new("#{msg}")
end
end
end
end
Call_Win 类
class Call_Win < Qt::Widget
def initialize(message)
super
@msg = message
setWindowTitle "Menu"
init_ui
resize 400, 600
move 401, 0
show
end
def init_ui
puts @msg
show(@msg)
end
def show(msg)
Qt::MessageBox.information self, "#{msg}", "#{msg}"
end
end