大家帮我看看,为什么我的脚本不能执行
#include <QtGui>
#include <QtUiTools>
#include <QtScript>
#include <QMessageBox>
class Testss {
public:
Testss(){};
~Testss(){};
void start()
{
Q_INIT_RESOURCE(ddd);
QScriptEngine engine;
QFile scriptFile(":/teste.js");
if(!scriptFile.open(QIODevice::ReadOnly)){
QMessageBox::warning(NULL,QObject::tr("open"),QObject::tr("open failed"));
}
engine.evaluate(scriptFile.readAll());
scriptFile.close();
QUiLoader loader;
QFile uiFile(":/teste.ui");
if(!uiFile.open(QIODevice::ReadOnly)){
QMessageBox::warning(0,QObject::tr("open"),QObject::tr("open failed"));
}
QWidget *ui = loader.load(&uiFile);
uiFile.close();
QScriptValue func = engine.evaluate("nextClass");
QScriptValue scriptUi = engine.newQObject(ui);
QScriptValue table = func.construct(QScriptValueList() << scriptUi);
if(engine.hasUncaughtException()) {
QScriptValue value = engine.uncaughtException();
QString lineNumber = QString("\nLine Number:%1\n").arg(engine.uncaughtExceptionLineNumber());
QStringList btList = engine.uncaughtExceptionBacktrace();
QString trace;
for(short i=0; i<btList.size(); ++i)
trace += btList.at(i);
QMessageBox::information(NULL, QObject::tr("Exception"), value.toString() + lineNumber + trace );
}
ui->show();
}
};
int main(int argc,char **argv)
{
QApplication app(argc, argv);
Testss w;
w.start();
return app.exec();
}
下面是js
function nextClass(ui)
{
this.ui = ui;
ui.pushButton.clicked.connect(this,this.showtext);
ui.pushButton1.clicked.connect(this,ui.close);
}
nextClass.prototype.showtext = function()
{
this.ui.textEdit.setText(this.ui.lineEdit.text);
}
下面是.ui
<ui version="4.0" >
<class>nextClass</class>
<widget class="QWidget" name="nextClass" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>502</width>
<height>288</height>
</rect>
</property>
<property name="windowTitle" >
<string>twoform</string>
</property>
<widget class="QPushButton" name="pushButton" >
<property name="geometry" >
<rect>
<x>110</x>
<y>200</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text" >
<string>PushButton</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton1" >
<property name="geometry" >
<rect>
<x>250</x>
<y>200</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text" >
<string>PushButton</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit" >
<property name="geometry" >
<rect>
<x>140</x>
<y>40</y>
<width>113</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QTextEdit" name="textEdit" >
<property name="geometry" >
<rect>
<x>140</x>
<y>90</y>
<width>191</width>
<height>64</height>
</rect>
</property>
</widget>
<action name="actionOpen" >
<property name="text" >
<string>open</string>
</property>
</action>
<action name="actionSend" >
<property name="text" >
<string>send</string>
</property>
</action>
<action name="actionQuit" >
<property name="text" >
<string>quit</string>
</property>
</action>
</widget>
<resources/>
<connections/>
<slots>
<slot>readyreader()</slot>
</slots>
</ui>
为什么我把类里Start函数里的代码放到main函数中脚本就能执行,而在放到函数中就不能呢