QtScript Javascript Object loses property

396 Views Asked by At

I create a QScriptEngine and set a QObject as global object that has some signals / slots. Then I load some script files and pass it to the engine (using evaluate). The script creates an object and connects some signals of the global object to the its functions.

Sadly the property (this.password) of the script object is cleared when its function gets called from the singal (its set during evaluate, I checked that).

Here is the script:

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

Any ideas why that may happen?

Greetings Ben

1

There are 1 best solutions below

2
On

Javascript objects are passed by reference. Are you modifying Bot.Password before calling chanservObject.auth?