0

我创建了一个 QScriptEngine 并将一个 QObject 设置为具有一些信号/插槽的全局对象。然后我加载一些脚本文件并将其传递给引擎(使用评估)。该脚本创建一个对象并将全局对象的一些信号连接到它的函数。

可悲的是,脚本对象的属性(this.password)在从信号调用其函数时被清除(它在评估期间设置,我检查过)。

这是脚本:

   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);
}

任何想法为什么会发生这种情况?

问候本

4

1 回答 1

0

Javascript 对象通过引用传递。Bot.Password打电话前要修改chanservObject.auth吗?

于 2012-05-16T18:41:10.113 回答