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  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Obsolete Members for QScriptEngine

The following class members are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

Public Functions

bool canEvaluate ( const QString & program ) const (obsolete)

Related Non-Members

QScriptValue qScriptValueFromValue ( QScriptEngine * engine, const T & value ) (obsolete)

Member Function Documentation

bool QScriptEngine::canEvaluate ( const QString & program ) const

Returns true if program can be evaluated; i.e. the code is sufficient to determine whether it appears to be a syntactically correct program, or contains a syntax error.

This function returns false if program is incomplete; i.e. the input is syntactically correct up to the point where the input is terminated.

Note that this function only does a static check of program; e.g. it does not check whether references to variables are valid, and so on.

A typical usage of canEvaluate() is to implement an interactive interpreter for QtScript. The user is repeatedly queried for individual lines of code; the lines are concatened internally, and only when canEvaluate() returns true for the resulting program is it passed to evaluate().

The following are some examples to illustrate the behavior of canEvaluate(). (Note that all example inputs are assumed to have an explicit newline as their last character, since otherwise the QtScript parser would automatically insert a semi-colon character at the end of the input, and this could cause canEvaluate() to produce different results.)

Given the input

 if (hello && world)
     print("hello world");

canEvaluate() will return true, since the program appears to be complete.

Given the input

 if (hello &&

canEvaluate() will return false, since the if-statement is not complete, but is syntactically correct so far.

Given the input

 0 = 0

canEvaluate() will return true, but evaluate() will throw a SyntaxError given the same input.

Given the input

 ./test.js

canEvaluate() will return true, even though the code is clearly not syntactically valid QtScript code. evaluate() will throw a SyntaxError when this code is evaluated.

Given the input

 foo["bar"]

canEvaluate() will return true, but evaluate() will throw a ReferenceError if foo is not defined in the script environment.

See also evaluate() and checkSyntax().

Related Non-Members

QScriptValue qScriptValueFromValue ( QScriptEngine * engine, const T & value )

Creates a QScriptValue using the given engine with the given value of template type T.

This function is equivalent to QScriptEngine::toScriptValue().

Note: This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.

This function was introduced in Qt 4.3.

See also QScriptEngine::toScriptValue() and qscriptvalue_cast().

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.8
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