我创建了一个QScriptEngine并将QObject设置为具有一些信号/槽的全局对象。然后我加载一些脚本文件并将其传递给引擎(使用evaluate)。该脚本创建一个对象,并将全局对象的一些信号连接到其函数。
遗憾的是,脚本对象的属性(this.password)在从singal调用它的函数时被清除(它在评估期间设置了它,我检查了它)。
这是脚本:
function Chanserv(password) {
this.password = password;
// print("#### Constructor local: " + password + " / global: " + Bot.Password);
}
Chanserv.prototype.test = function() {
// print("This is a test function / " + Bot.Password + " / " + this.password);
}
Chanserv.prototype.auth = function() {
print("#### entered auth function! " + this.password);
// if (this.password && this.password.length > 0) {
if (Bot.Password && Bot.Password.length > 0) {
Bot.sendMessage("nickserv", "identify " + Bot.Password);
// print("Trying to authenticate with " + this.password);
}
else {
print("Bot.Password undefined.");
// print("this.password = " + this.password
// + ", this.password.length = " + (this.password.length > 0));
}
}
var chanservObject = new Chanserv(Bot.Password); // this.password gets set
chanservObject.test();
try {
Bot.joinedChannel.connect(chanservObject.auth); // this.password is empty when called...
Bot.joinedChannel.connect(chanservObject.test);
// Bot.connected.connect(chanserv.auth);
}
catch (e) {
print(e);
}
为什么会出现这种情况?
问候本
答案 0 :(得分:0)
Javascript对象通过引用传递。您在致电Bot.Password
之前修改了chanservObject.auth
吗?