0

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

Chris
  • 17,119
  • 5
  • 57
  • 60
Ben
  • 934
  • 2
  • 8
  • 11

1 Answers1

0

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

  • Bot.Password is set on the javascript side before the script is load and evaluated. Code looks like 'Bot.Password = "myPass";'. As you can see in the previous post, Bot.Password is valid even when the function is called by the signal (used that as a fallback). this.password is 'undefined' when the function is called by the signal. – Ben May 16 '12 at 21:59
  • Sure, http://github.com/xeviox-com/qirk , the scripts aren't up to date, but the bot code itself should be... – Ben May 17 '12 at 22:27