Finally I got my script working.

I modify the implement of function()

Qt Code:
  1. void AD::function()
  2. {
  3. qDebug() << "This is a test";
  4. }
To copy to clipboard, switch view to plain text mode 

and the script file
Qt Code:
  1. AD.function();
To copy to clipboard, switch view to plain text mode 

after runt the script, I could find my qDebug() window shows
Qt Code:
  1. This is a test
  2. nan
To copy to clipboard, switch view to plain text mode 

The problem might go with the syntax error of my script file. Thanks for your help!