Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QScriptEngineAgent Class Reference
[QtScript module]

The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execution. More...

 #include <QScriptEngineAgent>

This class was introduced in Qt 4.4.

Public Types

Public Functions


Detailed Description

The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execution.

The QScriptEngineAgent class is the basis of tools that monitor and/or control the execution of a QScriptEngine, such as debuggers and profilers.

To process script loading and unloading events, reimplement the scriptLoad() and scriptUnload() functions. scriptLoad() is called after the input to QScriptEngine::evaluate() has been parsed, right before the given script is executed. The engine assigns each script an ID, which is available as one of the arguments to scriptLoad(); subsequently, other event handlers can use the ID to identify a particular script. One common usage of scriptLoad() is to retain the script text, filename and base line number (the original input to QScriptEngine::evaluate()), so that other event handlers can e.g. map a line number to the corresponding line of text.

scriptUnload() is called when the QScriptEngine has no further use for a script; the QScriptEngineAgent may at this point safely discard any resources associated with the script (such as the script text). Note that after scriptUnload() has been called, the QScriptEngine may reuse the relevant script ID for new scripts (i.e. as argument to a subsequent call to scriptLoad()).

Evaluating the following script will result in scriptUnload() being called immediately after evaluation has completed:

 var a = Math.random() + 2;

Evaluating the following script will \b{not} result in a call to scriptUnload() when evaluation has completed:

 function cube(a) {
     return a * a * a;
 }

 var a = cube(3);

The script isn't unloaded because it defines a function (cube) that remains in the script environment after evaluation has completed. If a subsequent script removed the cube function (e.g. by setting it to null), scriptUnload() would be called when the function is garbage collected. In general terms, a script isn't unloaded until the engine has determined that none of its contents is referenced.

To process script function calls and returns, reimplement the functionEntry() and functionExit() functions. functionEntry() is called when a script function is about to be executed; functionExit() is called when a script function is about to return, either normally or due to an exception.

To process individual script statements, reimplement positionChange(). positionChange() is called each time the engine is about to execute a new statement of a script, and thus offers the finest level of script monitoring.

To process exceptions, reimplement exceptionThrow() and exceptionCatch(). exceptionThrow() is called when a script exception is thrown, before it has been handled. exceptionCatch() is called when an exception handler is present, and execution is about to be resumed at the handler code.

See also QScriptEngine::setAgent() and QScriptContextInfo.


Member Type Documentation

enum QScriptEngineAgent::Extension

This enum specifies the possible extensions to a QScriptEngineAgent.

See also extension().


Member Function Documentation

QScriptEngineAgent::QScriptEngineAgent ( QScriptEngine * engine )

Constructs a QScriptEngineAgent object for the given engine.

The engine takes ownership of the agent.

Call QScriptEngine::setAgent() to make this agent the active agent.

QScriptEngineAgent::~QScriptEngineAgent ()   [virtual]

Destroys this QScriptEngineAgent.

void QScriptEngineAgent::contextPop ()   [virtual]

This function is called when the current script context is about to be popped.

The default implementation does nothing.

See also contextPush() and functionExit().

void QScriptEngineAgent::contextPush ()   [virtual]

This function is called when a new script context has been pushed.

The default implementation does nothing.

See also contextPop() and functionEntry().

QScriptEngine * QScriptEngineAgent::engine () const

Returns the QScriptEngine that this agent is associated with.

void QScriptEngineAgent::exceptionCatch ( qint64 scriptId, const QScriptValue & exception )   [virtual]

This function is called when the given exception is about to be caught, in the script identified by scriptId.

Reimplement this function if you want to handle this event.

The default implementation does nothing.

See also exceptionThrow().

void QScriptEngineAgent::exceptionThrow ( qint64 scriptId, const QScriptValue & exception, bool hasHandler )   [virtual]

This function is called when the given exception has occurred in the engine, in the script identified by scriptId. If the exception was thrown by a native Qt Script function, scriptId is -1.

If hasHandler is true, there is a catch or finally block that will handle the exception. If hasHandler is false, there is no handler for the exception.

Reimplement this function if you want to handle this event. For example, a debugger can notify the user when an uncaught exception occurs (i.e. hasHandler is false).

The default implementation does nothing.

See also exceptionCatch().

QVariant QScriptEngineAgent::extension ( Extension extension, const QVariant & argument = QVariant() )   [virtual]

This virtual function can be reimplemented in a QScriptEngineAgent subclass to provide support for extensions. The optional argument can be provided as input to the extension; the result must be returned in the form of a QVariant. You can call supportsExtension() to check if an extension is supported by the QScriptEngineAgent. By default, no extensions are supported, and this function returns an invalid QVariant.

See also supportsExtension().

void QScriptEngineAgent::functionEntry ( qint64 scriptId )   [virtual]

This function is called when a script function is called in the engine. If the script function is not a native Qt Script function, it resides in the script identified by scriptId; otherwise, scriptId is -1.

This function is called just before execution of the script function begins. You can obtain the QScriptContext associated with the function call with QScriptEngine::currentContext(). The arguments passed to the function are available.

Reimplement this function to handle this event. For example, a debugger implementation could reimplement this function (and functionExit()) to keep track of the call stack and provide step-over functionality.

The default implementation does nothing.

See also functionExit(), positionChange(), and QScriptEngine::currentContext().

void QScriptEngineAgent::functionExit ( qint64 scriptId, const QScriptValue & returnValue )   [virtual]

This function is called when the currently executing script function is about to return. If the script function is not a native Qt Script function, it resides in the script identified by scriptId; otherwise, scriptId is -1. The returnValue is the value that the script function will return.

This function is called just before the script function returns. You can still access the QScriptContext associated with the script function call with QScriptEngine::currentContext().

If the engine's hasUncaughtException() function returns true, the script function is exiting due to an exception; otherwise, the script function is returning normally.

Reimplement this function to handle this event; typically you will then also want to reimplement functionEntry().

The default implementation does nothing.

See also functionEntry() and QScriptEngine::hasUncaughtException().

void QScriptEngineAgent::positionChange ( qint64 scriptId, int lineNumber, int columnNumber )   [virtual]

This function is called when the engine is about to execute a new statement in the script identified by scriptId. The statement begins on the line and column specified by lineNumber and columnNumber. This event is not generated for native Qt Script functions.

Reimplement this function to handle this event. For example, a debugger implementation could reimplement this function to provide line-by-line stepping, and a profiler implementation could use it to count the number of times each statement is executed.

The default implementation does nothing.

See also scriptLoad() and functionEntry().

void QScriptEngineAgent::scriptLoad ( qint64 id, const QString & program, const QString & fileName, int baseLineNumber )   [virtual]

This function is called when the engine has parsed a script and has associated it with the given id. The id can be used to identify this particular script in subsequent event notifications.

program, fileName and baseLineNumber are the original arguments to the QScriptEngine::evaluate() call that triggered this event.

This function is called just before the script is about to be evaluated.

You can reimplement this function to record information about the script; for example, by retaining the script text, you can obtain the line of text corresponding to a line number in a subsequent call to positionChange().

The default implementation does nothing.

See also scriptUnload().

void QScriptEngineAgent::scriptUnload ( qint64 id )   [virtual]

This function is called when the engine has discarded the script identified by the given id.

You can reimplement this function to clean up any resources you have associated with the script.

The default implementation does nothing.

See also scriptLoad().

bool QScriptEngineAgent::supportsExtension ( Extension extension ) const   [virtual]

Returns true if the QScriptEngineAgent supports the given extension; otherwise, false is returned. By default, no extensions are supported.

See also extension().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 73
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
  7. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
Page suivante

Le Qt Developer Network au hasard

Logo

Combiner licence, à propos et fermer d'une autre manière

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.4
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web