diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
commit | f15b8a83e2e51955776a3f07cb85ebfc342dd8ef (patch) | |
tree | c5dc684986051654898db11ce73e03b9fec8db99 /doc/src/snippets/scriptdebugger.cpp | |
download | Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.zip Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.gz Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.bz2 |
Initial import of statemachine branch from the old kinetic repository
Diffstat (limited to 'doc/src/snippets/scriptdebugger.cpp')
-rw-r--r-- | doc/src/snippets/scriptdebugger.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/src/snippets/scriptdebugger.cpp b/doc/src/snippets/scriptdebugger.cpp new file mode 100644 index 0000000..a1889d5 --- /dev/null +++ b/doc/src/snippets/scriptdebugger.cpp @@ -0,0 +1,64 @@ + +#include <QtGui> +#include <QtScript> +#include <QtScriptTools> + +// 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(); +} + |