Qt 4.8
|
The QScriptEngineDebugger class provides a QScriptEngine debugger. More...
#include <qscriptenginedebugger.h>
Public Types | |
enum | DebuggerAction { InterruptAction, ContinueAction, StepIntoAction, StepOverAction, StepOutAction, RunToCursorAction, RunToNewScriptAction, ToggleBreakpointAction, ClearDebugOutputAction, ClearErrorLogAction, ClearConsoleAction, FindInScriptAction, FindNextInScriptAction, FindPreviousInScriptAction, GoToLineAction } |
This enum specifies the action that the action() function should retrieve. More... | |
enum | DebuggerState { RunningState, SuspendedState } |
This enum specifies the current state of the debugger. More... | |
enum | DebuggerWidget { ConsoleWidget, StackWidget, ScriptsWidget, LocalsWidget, CodeWidget, CodeFinderWidget, BreakpointsWidget, DebugOutputWidget, ErrorLogWidget } |
This enum decides the widget that the widget() function should retrieve. More... | |
Signals | |
void | evaluationResumed () |
This signal is emitted when the debugger has resumed script evaluation (e. More... | |
void | evaluationSuspended () |
This signal is emitted when the debugger has suspended script evaluation for whatever reason (e. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
QAction * | action (DebuggerAction action) const |
Returns a pointer to the specified action. More... | |
void | attachTo (QScriptEngine *engine) |
Attaches to the given engine. More... | |
bool | autoShowStandardWindow () const |
Returns whether the standard debugger window is automatically shown when evaluation is suspended. More... | |
QMenu * | createStandardMenu (QWidget *parent=0) |
Creates a standard debugger menu with the given parent. More... | |
QToolBar * | createStandardToolBar (QWidget *parent=0) |
Creates a standard debugger toolbar with the given parent. More... | |
void | detach () |
Detaches from the current script engine, if any. More... | |
QScriptEngineDebugger (QObject *parent=0) | |
Constructs a new QScriptEngineDebugger object with the given parent. More... | |
void | setAutoShowStandardWindow (bool autoShow) |
Sets whether the standard debugger window is automatically shown when evaluation is suspended. More... | |
QMainWindow * | standardWindow () const |
Returns a main window with a standard configuration of the debugger's components. More... | |
DebuggerState | state () const |
Returns the current state of the debugger. More... | |
QWidget * | widget (DebuggerWidget widget) const |
Returns a pointer to the instance of the specified standard widget. More... | |
~QScriptEngineDebugger () | |
Destroys this QScriptEngineDebugger. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The QScriptEngineDebugger class provides a QScriptEngine debugger.
The QScriptEngineDebugger class provides a debugger that can be embedded into Qt applications that use Qt Script. The debugger enables the application user to inspect the state of the script environment and control script execution.
To attach the debugger to a script engine, call the attachTo() function.
Once the debugger has been attached to a script engine, you can proceed to evaluate scripts as usual, e.g. by calling QScriptEngine::evaluate(). The debugger will be triggered when an uncaught exception occurs, or when a debugger
statement is encountered in a script. It is also possible to interrupt script evaluation at an arbitrary time by triggering the InterruptAction. For instance, to start the debugger when script evaluation starts, you trigger the action before you begin to QScriptEngine::evaluate() the script.
By default, the standard debugger window is shown when evaluation is suspended. This can be changed by calling the setAutoShowStandardWindow() function.
The debugger defines a set of actions that are available, such as stopping execution or printing the contents of a variable. It also provides a set of widgets (components) that display the information available from the debugger and that trigger the actions on request. The actions available are identified by the DebuggerAction enum, and the widgets are identified by the DebuggerWidget enum.
Access to the individual debugger widgets is provided by the widget() function. This makes it possible to arrange the widgets in a custom manner. Similarly, the action() function provides access to the various debugger actions.
The createStandardToolBar() function creates a standard toolbar, and the createStandardMenu() function creates a standard menu; these functions can be useful if you are creating a custom debugger configuration.
The evaluationSuspended() signal is emitted when the debugger has suspended script evaluation and entered interactive mode, i.e., the mode in which it accepts input from the user. The evaluationResumed() signal is emitted when script evaluation is resumed, i.e, when execution control is given back to the script engine. The state() function returns the debugger's current state.
When calling QScriptEngine::evaluate() it is useful to pass a descriptive script name (file name) as second argument, as this is the name that will be displayed by the debugger in the ScriptsWidget; if a name is not passed, the script will be labelled "anonymous".
When evaluation is suspended, the debugger will also suspend the event loop of the script. In the following snippet, the call to QScriptEngine::evaluate() causes the debugger to be triggered, and the function call does not return until the user has finished interacting with the debugger.
When the Qt Script debugger is running, the C++ application itself is not "frozen". This means that it is possible that more scripts are evaluated, even though the debugger has suspended evaluation of the current script evaluation. For example, a C++ timer might trigger that causes a script function to be called, or the user might click on a button in the main application user interface whose clicked() signal is connected to a script function. This kind of nested evaluation is permitted. The debugger will enter interactive mode for the new script if an exception is thrown or a breakpoint is reached. Note that it will not stop when encountering debugger
statements.
Nested evaluation requires some thought when deciding how the debugger is presented to the user; for example, whether a modal dialog is suitable, or whether some parts of the main application user interface should be disabled while the debugger is running.
Debugging inside of a paintEvent() is currently not supported. If you need to debug painting-related script code, that code should be evaluated outside of the C++ paintEvent(), e.g. by rendering to an image, like the Context2D and Tetrix QtScript examples do. This will make the code safe for debugging.
The debugger adds some special properties to the script engine: __FILE__
holds the name of the script in which the current evaluation occurs, and __LINE__
holds the current line number. These are useful when doing print()-style debugging (the messages appear in the debugger's debug output widget).
The Qt Script Debugger Manual describes how to use the debugger. The Context2D Example{Context2D example} shows how to integrate the debugger in applications.
Definition at line 63 of file qscriptenginedebugger.h.
This enum specifies the action that the action() function should retrieve.
The actions retrieved can be connected to any slot and connected to any widget. Please see the Qt Script Debugger Manual's Console Command Reference for a detailed description of these actions.
Definition at line 79 of file qscriptenginedebugger.h.
This enum specifies the current state of the debugger.
Enumerator | |
---|---|
RunningState | |
SuspendedState |
Definition at line 97 of file qscriptenginedebugger.h.
This enum decides the widget that the widget() function should retrieve.
We treat these widgets in more detail in the Qt Script Debugger Manual.
print()
script function. Enumerator | |
---|---|
ConsoleWidget | |
StackWidget | |
ScriptsWidget | |
LocalsWidget | |
CodeWidget | |
CodeFinderWidget | |
BreakpointsWidget | |
DebugOutputWidget | |
ErrorLogWidget |
Definition at line 67 of file qscriptenginedebugger.h.
QScriptEngineDebugger::QScriptEngineDebugger | ( | QObject * | parent = 0 | ) |
Constructs a new QScriptEngineDebugger object with the given parent.
To attach a QScriptEngine to the debugger, use attachTo() function.
Definition at line 368 of file qscriptenginedebugger.cpp.
QScriptEngineDebugger::~QScriptEngineDebugger | ( | ) |
Destroys this QScriptEngineDebugger.
Definition at line 376 of file qscriptenginedebugger.cpp.
QAction * QScriptEngineDebugger::action | ( | DebuggerAction | action | ) | const |
Returns a pointer to the specified action.
The actions available are given by the DebuggerAction enum.
With this function, you can add the actions to your own widgets, toolbars, and menus. It is also convenient if you, for example, wish to spice things up with your own groovy icons. The code example below shows how to add actions to a QToolBar.
Note that QScriptEngineDebugger has already added the actions to its standard widgets and standard window.
Definition at line 479 of file qscriptenginedebugger.cpp.
Referenced by standardWindow().
void QScriptEngineDebugger::attachTo | ( | QScriptEngine * | engine | ) |
Attaches to the given engine.
The debugger will install a custom agent (using QScriptEngine::setAgent()) to monitor the engine. While the debugger is attached, you should not change the agent; however, if you do have to perform additional monitoring, you must set a proxy agent that forwards all events to the debugger's agent.
Definition at line 391 of file qscriptenginedebugger.cpp.
bool QScriptEngineDebugger::autoShowStandardWindow | ( | ) | const |
Returns whether the standard debugger window is automatically shown when evaluation is suspended.
The default is true.
Definition at line 493 of file qscriptenginedebugger.cpp.
Creates a standard debugger menu with the given parent.
Returns the new menu object.
Definition at line 637 of file qscriptenginedebugger.cpp.
Referenced by standardWindow().
Creates a standard debugger toolbar with the given parent.
Returns the new toolbar object.
Definition at line 651 of file qscriptenginedebugger.cpp.
Referenced by standardWindow().
void QScriptEngineDebugger::detach | ( | ) |
Detaches from the current script engine, if any.
Definition at line 410 of file qscriptenginedebugger.cpp.
Referenced by attachTo().
|
signal |
This signal is emitted when the debugger has resumed script evaluation (e.
g. the user gave the "continue" command).
\sa evaluationSuspended()
|
signal |
This signal is emitted when the debugger has suspended script evaluation for whatever reason (e.
g. due to an uncaught script exception, or due to a breakpoint being triggered).
Referenced by setAutoShowStandardWindow().
void QScriptEngineDebugger::setAutoShowStandardWindow | ( | bool | autoShow | ) |
Sets whether the standard debugger window is automatically shown when evaluation is suspended.
If autoShow is true, the window will be automatically shown, otherwise it will not.
Definition at line 504 of file qscriptenginedebugger.cpp.
QMainWindow * QScriptEngineDebugger::standardWindow | ( | ) | const |
Returns a main window with a standard configuration of the debugger's components.
Definition at line 526 of file qscriptenginedebugger.cpp.
QScriptEngineDebugger::DebuggerState QScriptEngineDebugger::state | ( | ) | const |
Returns the current state of the debugger.
Definition at line 430 of file qscriptenginedebugger.cpp.
Referenced by standardWindow().
QWidget * QScriptEngineDebugger::widget | ( | DebuggerWidget | widget | ) | const |
Returns a pointer to the instance of the specified standard widget.
The widgets available are defined by the DebuggerWidget enum.
A main window containing all widgets is returned by standardWindow(). If you do not want to use this window, you can fetch the individual widgets with this function. For instance, the code example below shows how to set up a layout containing a code window and a stack widget.
Note that you need to set setAutoShowStandardWindow() to false; if not, the standard window will be shown regardless.
Definition at line 456 of file qscriptenginedebugger.cpp.
Referenced by standardWindow().