示例#1
0
// Perhaps shpw entire example for getting debugger up with script
int main(int argv, char **args)
{
    QApplication app(argv, args);

     QString fileName("helloscript.qs");
     QFile scriptFile(fileName);
     scriptFile.open(QIODevice::ReadOnly);
     QTextStream stream(&scriptFile);
     QString contents = stream.readAll();
     scriptFile.close();

    QScriptEngine *engine = new QScriptEngine();

    QScriptEngineDebugger *debugger = new QScriptEngineDebugger();
    debugger->attachTo(engine);

    // Set up configuration with only stack and code
    QWidget *widget = new QWidget;
//![0]
    QWidget *codeWindow = debugger->widget(QScriptEngineDebugger::CodeWidget);
    QWidget *stackWidget = debugger->widget(QScriptEngineDebugger::StackWidget);

    QLayout *layout = new QHBoxLayout;
    layout->addWidget(codeWindow);
    layout->addWidget(stackWidget);
//![0]

//![1]
    QAction *continueAction = debugger->action(QScriptEngineDebugger::ContinueAction);
    QAction *stepOverAction = debugger->action(QScriptEngineDebugger::StepOverAction);
    QAction *stepIntoAction = debugger->action(QScriptEngineDebugger::StepIntoAction);

    QToolBar *toolBar = new QToolBar;
    toolBar->addAction(continueAction);
//![1]
    toolBar->addAction(stepOverAction);
    toolBar->addAction(stepIntoAction);

    layout->addWidget(toolBar);
    continueAction->setIcon(QIcon("copy.png"));

    debugger->setAutoShowStandardWindow(false);

    widget->setLayout(layout);
    widget->show();

     QPushButton button;
     QScriptValue scriptButton = engine->newQObject(&button);
     engine->globalObject().setProperty("button", scriptButton);

//![2]
     debugger->action(QScriptEngineDebugger::InterruptAction)->trigger();
     engine->evaluate(contents, fileName);
//![2]

    return app.exec();
}
	bool execute()
	{
		TFilePath fp;
		QString fileName = "helloworld.qs";
		QFile scriptFile(QString::fromStdWString(fp.getWideString()));
		if (!scriptFile.open(QIODevice::ReadOnly)) {
			DVGui::MsgBox(DVGui::WARNING, QObject::tr("File not found"));
			return false;
		} else {
			QTextStream stream(&scriptFile);
			QString contents = stream.readAll();
			scriptFile.close();
			QScriptEngine myEngine;
			QScriptEngineDebugger debugger;
			debugger.attachTo(&myEngine);

			QScriptValue fFoo = myEngine.newFunction(foo);
			QScriptValue fGetLevel = myEngine.newFunction(getLevel);

			myEngine.globalObject().setProperty("foo", fFoo);
			myEngine.globalObject().setProperty("getLevel", fGetLevel);
			debugger.action(QScriptEngineDebugger::InterruptAction)->trigger();
			myEngine.evaluate(contents, fileName);
		}
		return true;
	}
示例#3
0
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(tetrix);

//! [1]
    QApplication app(argc, argv);
    QScriptEngine engine;

    QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get());
    Qt.setProperty("App", engine.newQObject(&app));
    engine.globalObject().setProperty("Qt", Qt);
//! [1]

#ifndef QT_NO_SCRIPTTOOLS
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    QMainWindow *debugWindow = debugger.standardWindow();
    debugWindow->resize(1024, 640);
#endif

//! [2]
    evaluateFile(engine, ":/tetrixpiece.js");
    evaluateFile(engine, ":/tetrixboard.js");
    evaluateFile(engine, ":/tetrixwindow.js");
//! [2]

//! [3]
    TetrixUiLoader loader;
    QFile uiFile(":/tetrixwindow.ui");
    uiFile.open(QIODevice::ReadOnly);
    QWidget *ui = loader.load(&uiFile);
    uiFile.close();

    QScriptValue ctor = engine.evaluate("TetrixWindow");
    QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
    QScriptValue tetrix = ctor.construct(QScriptValueList() << scriptUi);
//! [3]

    QPushButton *debugButton = qFindChild<QPushButton*>(ui, "debugButton");
#ifndef QT_NO_SCRIPTTOOLS
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugger.action(QScriptEngineDebugger::InterruptAction),
                     SIGNAL(triggered()));
    QObject::connect(debugButton, SIGNAL(clicked()),
                     debugWindow, SLOT(show()));
#else
    debugButton->hide();
#endif

//! [4]
    ui->resize(550, 370);
    ui->show();

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    return app.exec();
//! [4]
}
    bool QtScriptEngine::runScript(const QString& script, const QString& name, RunMode mode)
    {
        MyQScriptEngine engine(this);

        map<ADM_dynMuxer*, Muxer*> muxers;
        map<ADM_videoEncoder6*, VideoEncoder*> videoEncoders;

#ifdef QT_SCRIPTTOOLS
        QScriptEngineDebugger debugger;

        if (mode == IScriptEngine::Debug || mode == IScriptEngine::DebugOnError)
        {
            debugger.attachTo(&engine);
            debugger.standardWindow()->setWindowTitle(QT_TR_NOOP("Avidemux Script Debugger"));
            debugger.standardWindow()->setWindowModality(Qt::ApplicationModal);

            if (mode == IScriptEngine::Debug)
            {
                debugger.action(QScriptEngineDebugger::InterruptAction)->trigger();
            }
        }

#endif

        this->registerAudioEncoderPlugins(&engine);
        this->registerMuxerPlugins(&engine, &muxers);
        this->registerVideoEncoderPlugins(&engine, &videoEncoders);
        this->registerVideoFilterPlugins(&engine);
		this->registerDialogClasses(&engine);
        this->registerScriptClasses(&engine, &muxers, &videoEncoders);

        QScriptValue result = engine.evaluate(script, name);
        bool success = false;

        if (engine.hasUncaughtException())
        {
            QString errorDetails = (QString("Unable to process script.\n\nLine number: %1\n").arg(
                                        engine.uncaughtExceptionLineNumber()) + result.toString());

            this->callEventHandlers(IScriptEngine::Error, NULL, -1, (QString("Script error ") + errorDetails).toUtf8().constData());
            success = false;
        }
        else
        {
            this->callEventHandlers(IScriptEngine::Information, NULL, -1, (QString("Result: ") + result.toString()).toUtf8().constData());
            success = true;
        }

        return success;
    }
示例#5
0
void tst_QScriptEngineDebugger::action()
{
#if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600
    QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll);
#endif

    QScriptEngine engine;
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    QList<QScriptEngineDebugger::DebuggerAction> actions;
    actions
        << QScriptEngineDebugger::InterruptAction
        << QScriptEngineDebugger::ContinueAction
        << QScriptEngineDebugger::StepIntoAction
        << QScriptEngineDebugger::StepOverAction
        << QScriptEngineDebugger::StepOutAction
        << QScriptEngineDebugger::RunToCursorAction
        << QScriptEngineDebugger::RunToNewScriptAction
        << QScriptEngineDebugger::ToggleBreakpointAction
        << QScriptEngineDebugger::ClearDebugOutputAction
        << QScriptEngineDebugger::ClearErrorLogAction
        << QScriptEngineDebugger::ClearConsoleAction
        << QScriptEngineDebugger::FindInScriptAction
        << QScriptEngineDebugger::FindNextInScriptAction
        << QScriptEngineDebugger::FindPreviousInScriptAction
        << QScriptEngineDebugger::GoToLineAction;
    QList<QAction*> lst;
    for (int i = 0; i < actions.size(); ++i) {
        QScriptEngineDebugger::DebuggerAction da = actions.at(i);
        QAction *act = debugger.action(da);
        QVERIFY(act != 0);
        QCOMPARE(act, debugger.action(da));
        QCOMPARE(act->parent(), (QObject*)&debugger);
        QVERIFY(lst.indexOf(act) == -1);
        lst.append(act);
    }
}
示例#6
0
void tst_QScriptEngineDebugger::debuggerSignals()
{
#if defined(Q_OS_WINCE) && _WIN32_WCE < 0x600
    QSKIP("skipped due to high mem usage until task 261062 is fixed", SkipAll);
#endif

    QScriptEngine engine;
    QScriptEngineDebugger debugger;
    debugger.attachTo(&engine);
    debugger.setAutoShowStandardWindow(false);
    QSignalSpy evaluationSuspendedSpy(&debugger, SIGNAL(evaluationSuspended()));
    QSignalSpy evaluationResumedSpy(&debugger, SIGNAL(evaluationResumed()));
    QObject::connect(&debugger, SIGNAL(evaluationSuspended()),
                     debugger.action(QScriptEngineDebugger::ContinueAction),
                     SLOT(trigger()));
    engine.evaluate("123");
    QCOMPARE(evaluationSuspendedSpy.count(), 0);
    QCOMPARE(evaluationResumedSpy.count(), 0);
    engine.evaluate("debugger");
    QCoreApplication::processEvents();
    QCOMPARE(evaluationSuspendedSpy.count(), 1);
    QCOMPARE(evaluationResumedSpy.count(), 1);
}