Qt 4.8
Public Types | Public Functions | Properties | Friends | List of all members
QScriptContextInfo Class Reference

The QScriptContextInfo class provides additional information about a QScriptContext. More...

#include <qscriptcontextinfo.h>

Public Types

enum  FunctionType { ScriptFunction, QtFunction, QtPropertyFunction, NativeFunction }
 This enum specifies the type of function being called. More...
 

Public Functions

QT_DEPRECATED int columnNumber () const
 
QString fileName () const
 Returns the name of the file where the code being executed was defined, if available; otherwise returns an empty string. More...
 
int functionEndLineNumber () const
 Returns the line number where the definition of the called function ends, or -1 if the line number is not available. More...
 
int functionMetaIndex () const
 Returns the meta index of the called function, or -1 if the meta index is not available. More...
 
QString functionName () const
 Returns the name of the called function, or an empty string if the name is not available. More...
 
QStringList functionParameterNames () const
 Returns the names of the formal parameters of the called function, or an empty QStringList if the parameter names are not available. More...
 
int functionStartLineNumber () const
 Returns the line number where the definition of the called function starts, or -1 if the line number is not available. More...
 
FunctionType functionType () const
 Returns the type of the called function. More...
 
bool isNull () const
 Returns true if this QScriptContextInfo is null, i.e. More...
 
int lineNumber () const
 Returns the line number corresponding to the statement being executed, or -1 if the line number is not available. More...
 
bool operator!= (const QScriptContextInfo &other) const
 Returns true if this QScriptContextInfo is not equal to the other info, otherwise returns false. More...
 
QScriptContextInfooperator= (const QScriptContextInfo &other)
 Assigns the other info to this QScriptContextInfo, and returns a reference to this QScriptContextInfo. More...
 
bool operator== (const QScriptContextInfo &other) const
 Returns true if this QScriptContextInfo is equal to the other info, otherwise returns false. More...
 
 QScriptContextInfo (const QScriptContext *context)
 Constructs a new QScriptContextInfo from the given context. More...
 
 QScriptContextInfo (const QScriptContextInfo &other)
 Constructs a new QScriptContextInfo from the other info. More...
 
 QScriptContextInfo ()
 Constructs a null QScriptContextInfo. More...
 
qint64 scriptId () const
 Returns the ID of the script where the code being executed was defined, or -1 if the ID is not available (i.e. More...
 
 ~QScriptContextInfo ()
 Destroys the QScriptContextInfo. More...
 

Properties

QExplicitlySharedDataPointer< QScriptContextInfoPrivated_ptr
 

Friends

Q_SCRIPT_EXPORT QDataStreamoperator<< (QDataStream &, const QScriptContextInfo &)
 Writes the given info to the specified stream. More...
 
Q_SCRIPT_EXPORT QDataStreamoperator>> (QDataStream &, QScriptContextInfo &)
 Reads a QScriptContextInfo from the specified stream into the given info. More...
 

Detailed Description

The QScriptContextInfo class provides additional information about a QScriptContext.

Since
4.4

QScriptContextInfo is typically used for debugging purposes. It can provide information about the code being executed, such as the type of the called function, and the original source code location of the current statement.

If the called function is executing Qt Script code, you can obtain the script location with the functions fileName() and lineNumber().

You can obtain the starting line number and ending line number of a Qt Script function definition with functionStartLineNumber() and functionEndLineNumber(), respectively.

For Qt Script functions and Qt methods (e.g. slots), you can call functionParameterNames() to get the names of the formal parameters of the function.

For Qt methods and Qt property accessors, you can obtain the index of the underlying QMetaMethod or QMetaProperty by calling functionMetaIndex().

See also
QScriptContext, QScriptEngineAgent

Definition at line 45 of file qscriptcontextinfo.h.

Enumerations

◆ FunctionType

This enum specifies the type of function being called.

  • ScriptFunction The function is a Qt Script function, i.e. it was defined through a call to QScriptEngine::evaluate().
  • QtFunction The function is a Qt function (a signal, slot or method).
  • QtPropertyFunction The function is a Qt property getter or setter.
  • NativeFunction The function is a built-in Qt Script function, or it was defined through a call to QScriptEngine::newFunction().
Enumerator
ScriptFunction 
QtFunction 
QtPropertyFunction 
NativeFunction 

Definition at line 53 of file qscriptcontextinfo.h.

Constructors and Destructors

◆ QScriptContextInfo() [1/3]

QScriptContextInfo::QScriptContextInfo ( const QScriptContext context)

Constructs a new QScriptContextInfo from the given context.

The relevant information is extracted from the context at construction time; i.e. if you continue script execution in the context, the new state of the context will not be reflected in a previously created QScriptContextInfo.

Definition at line 240 of file qscriptcontextinfo.cpp.

241  : d_ptr(0)
242 {
243  if (context) {
244  d_ptr = new QScriptContextInfoPrivate(context);
245  d_ptr->q_ptr = this;
246  }
247 }
QExplicitlySharedDataPointer< QScriptContextInfoPrivate > d_ptr

◆ QScriptContextInfo() [2/3]

QScriptContextInfo::QScriptContextInfo ( const QScriptContextInfo other)

Constructs a new QScriptContextInfo from the other info.

Definition at line 252 of file qscriptcontextinfo.cpp.

253  : d_ptr(other.d_ptr)
254 {
255 }
QExplicitlySharedDataPointer< QScriptContextInfoPrivate > d_ptr

◆ QScriptContextInfo() [3/3]

QScriptContextInfo::QScriptContextInfo ( )

Constructs a null QScriptContextInfo.

See also
isNull()

Definition at line 262 of file qscriptcontextinfo.cpp.

263  : d_ptr(0)
264 {
265 }
QExplicitlySharedDataPointer< QScriptContextInfoPrivate > d_ptr

◆ ~QScriptContextInfo()

QScriptContextInfo::~QScriptContextInfo ( )

Destroys the QScriptContextInfo.

Definition at line 270 of file qscriptcontextinfo.cpp.

271 {
272 }

Functions

◆ columnNumber()

int QScriptContextInfo::columnNumber ( ) const

Definition at line 336 of file qscriptcontextinfo.cpp.

Referenced by contextInfoToScriptValue(), and operator<<().

337 {
338  Q_D(const QScriptContextInfo);
339  if (!d)
340  return -1;
341  return d->columnNumber;
342 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ fileName()

QString QScriptContextInfo::fileName ( ) const

Returns the name of the file where the code being executed was defined, if available; otherwise returns an empty string.

For Qt Script code, this function returns the fileName argument that was passed to QScriptEngine::evaluate().

See also
lineNumber(), functionName()

Definition at line 308 of file qscriptcontextinfo.cpp.

Referenced by QJSDebuggerAgent::backtrace(), contextInfoToScriptValue(), QScriptDebuggerStackModel::data(), operator<<(), QJSDebuggerAgentPrivate::positionChange(), QDeclarativeValueTypeScriptClass::setProperty(), QDeclarativeObjectScriptClass::setProperty(), and QScriptContext::toString().

309 {
310  Q_D(const QScriptContextInfo);
311  if (!d)
312  return QString();
313  return d->fileName;
314 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionEndLineNumber()

int QScriptContextInfo::functionEndLineNumber ( ) const

Returns the line number where the definition of the called function ends, or -1 if the line number is not available.

The ending line number is only available if the functionType() is ScriptFunction.

See also
functionStartLineNumber()

Definition at line 402 of file qscriptcontextinfo.cpp.

Referenced by QScriptDebuggerCommandExecutor::execute(), and operator<<().

403 {
404  Q_D(const QScriptContextInfo);
405  if (!d)
406  return -1;
407  return d->functionEndLineNumber;
408 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionMetaIndex()

int QScriptContextInfo::functionMetaIndex ( ) const

Returns the meta index of the called function, or -1 if the meta index is not available.

The meta index is only available if the functionType() is QtFunction or QtPropertyFunction. For QtFunction, the meta index can be passed to QMetaObject::method() to obtain the corresponding method definition; for QtPropertyFunction, the meta index can be passed to QMetaObject::property() to obtain the corresponding property definition.

See also
QScriptContext::thisObject()

Definition at line 437 of file qscriptcontextinfo.cpp.

Referenced by operator<<().

438 {
439  Q_D(const QScriptContextInfo);
440  if (!d)
441  return -1;
442  return d->functionMetaIndex;
443 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionName()

QString QScriptContextInfo::functionName ( ) const

Returns the name of the called function, or an empty string if the name is not available.

For script functions of type QtPropertyFunction, this function always returns the name of the property; you can use QScriptContext::argumentCount() to differentiate between reads and writes.

See also
fileName(), functionType()

Definition at line 355 of file qscriptcontextinfo.cpp.

Referenced by QJSDebuggerAgent::backtrace(), contextInfoToScriptValue(), QScriptDebuggerStackModel::data(), operator<<(), and QScriptContext::toString().

356 {
357  Q_D(const QScriptContextInfo);
358  if (!d)
359  return QString();
360  return d->functionName;
361 }
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionParameterNames()

QStringList QScriptContextInfo::functionParameterNames ( ) const

Returns the names of the formal parameters of the called function, or an empty QStringList if the parameter names are not available.

See also
QScriptContext::argument()

Definition at line 416 of file qscriptcontextinfo.cpp.

Referenced by operator<<(), and QScriptContext::toString().

417 {
418  Q_D(const QScriptContextInfo);
419  if (!d)
420  return QStringList();
421  return d->parameterNames;
422 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionStartLineNumber()

int QScriptContextInfo::functionStartLineNumber ( ) const

Returns the line number where the definition of the called function starts, or -1 if the line number is not available.

The starting line number is only available if the functionType() is ScriptFunction.

See also
functionEndLineNumber(), fileName()

Definition at line 385 of file qscriptcontextinfo.cpp.

Referenced by QJSDebuggerAgent::backtrace(), QScriptDebuggerCommandExecutor::execute(), operator<<(), QDeclarativeValueTypeScriptClass::setProperty(), and QDeclarativeObjectScriptClass::setProperty().

386 {
387  Q_D(const QScriptContextInfo);
388  if (!d)
389  return -1;
390  return d->functionStartLineNumber;
391 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ functionType()

QScriptContextInfo::FunctionType QScriptContextInfo::functionType ( ) const

Returns the type of the called function.

See also
functionName(), QScriptContext::callee()

Definition at line 368 of file qscriptcontextinfo.cpp.

Referenced by QJSDebuggerAgent::backtrace(), QScriptDebuggerStackModel::data(), operator<<(), QJSDebuggerAgentPrivate::positionChange(), and QScriptContext::toString().

369 {
370  Q_D(const QScriptContextInfo);
371  if (!d)
372  return NativeFunction;
373  return d->functionType;
374 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ isNull()

bool QScriptContextInfo::isNull ( ) const

Returns true if this QScriptContextInfo is null, i.e.

does not contain any information.

Definition at line 449 of file qscriptcontextinfo.cpp.

450 {
451  Q_D(const QScriptContextInfo);
452  return (d == 0);
453 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ lineNumber()

int QScriptContextInfo::lineNumber ( ) const

Returns the line number corresponding to the statement being executed, or -1 if the line number is not available.

The line number is only available if Qt Script code is being executed.

See also
columnNumber(), fileName()

Definition at line 325 of file qscriptcontextinfo.cpp.

Referenced by QJSDebuggerAgent::backtrace(), contextInfoToScriptValue(), QScriptDebuggerStackModel::data(), operator<<(), and QScriptContext::toString().

326 {
327  Q_D(const QScriptContextInfo);
328  if (!d)
329  return -1;
330  return d->lineNumber;
331 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ operator!=()

bool QScriptContextInfo::operator!= ( const QScriptContextInfo other) const

Returns true if this QScriptContextInfo is not equal to the other info, otherwise returns false.

Definition at line 483 of file qscriptcontextinfo.cpp.

484 {
485  return !(*this == other);
486 }

◆ operator=()

QScriptContextInfo & QScriptContextInfo::operator= ( const QScriptContextInfo other)

Assigns the other info to this QScriptContextInfo, and returns a reference to this QScriptContextInfo.

Definition at line 278 of file qscriptcontextinfo.cpp.

279 {
280  d_ptr = other.d_ptr;
281  return *this;
282 }
QExplicitlySharedDataPointer< QScriptContextInfoPrivate > d_ptr

◆ operator==()

bool QScriptContextInfo::operator== ( const QScriptContextInfo other) const

Returns true if this QScriptContextInfo is equal to the other info, otherwise returns false.

Definition at line 459 of file qscriptcontextinfo.cpp.

460 {
461  Q_D(const QScriptContextInfo);
462  const QScriptContextInfoPrivate *od = other.d_func();
463  if (d == od)
464  return true;
465  if (!d || !od)
466  return false;
467  return ((d->scriptId == od->scriptId)
468  && (d->lineNumber == od->lineNumber)
469  && (d->columnNumber == od->columnNumber)
470  && (d->fileName == od->fileName)
471  && (d->functionName == od->functionName)
472  && (d->functionType == od->functionType)
473  && (d->functionStartLineNumber == od->functionStartLineNumber)
474  && (d->functionEndLineNumber == od->functionEndLineNumber)
475  && (d->functionMetaIndex == od->functionMetaIndex)
476  && (d->parameterNames == od->parameterNames));
477 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QScriptContextInfo::FunctionType functionType
The QScriptContextInfo class provides additional information about a QScriptContext.

◆ scriptId()

qint64 QScriptContextInfo::scriptId ( ) const

Returns the ID of the script where the code being executed was defined, or -1 if the ID is not available (i.e.

a native function is being executed).

See also
QScriptEngineAgent::scriptLoad()

Definition at line 291 of file qscriptcontextinfo.cpp.

Referenced by contextInfoToScriptValue(), QScriptDebuggerStackModel::data(), and operator<<().

292 {
293  Q_D(const QScriptContextInfo);
294  if (!d)
295  return -1;
296  return d->scriptId;
297 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QScriptContextInfo class provides additional information about a QScriptContext.

Friends and Related Functions

◆ operator<<

QDataStream & operator<< ( QDataStream stream,
const QScriptContextInfo info 
)
friend

Writes the given info to the specified stream.

Since
4.4

Definition at line 499 of file qscriptcontextinfo.cpp.

500 {
501  out << info.scriptId();
502  out << (qint32)info.lineNumber();
503  out << (qint32)info.columnNumber();
504 
505  out << (quint32)info.functionType();
506  out << (qint32)info.functionStartLineNumber();
507  out << (qint32)info.functionEndLineNumber();
508  out << (qint32)info.functionMetaIndex();
509 
510  out << info.fileName();
511  out << info.functionName();
512  out << info.functionParameterNames();
513 
514  return out;
515 }
int qint32
Definition: qglobal.h:937
int functionEndLineNumber() const
Returns the line number where the definition of the called function ends, or -1 if the line number is...
QT_DEPRECATED int columnNumber() const
int functionMetaIndex() const
Returns the meta index of the called function, or -1 if the meta index is not available.
QString fileName() const
Returns the name of the file where the code being executed was defined, if available; otherwise retur...
int lineNumber() const
Returns the line number corresponding to the statement being executed, or -1 if the line number is no...
int functionStartLineNumber() const
Returns the line number where the definition of the called function starts, or -1 if the line number ...
QStringList functionParameterNames() const
Returns the names of the formal parameters of the called function, or an empty QStringList if the par...
unsigned int quint32
Definition: qglobal.h:938
FunctionType functionType() const
Returns the type of the called function.
qint64 scriptId() const
Returns the ID of the script where the code being executed was defined, or -1 if the ID is not availa...
QString functionName() const
Returns the name of the called function, or an empty string if the name is not available.

◆ operator>>

QDataStream & operator>> ( QDataStream stream,
QScriptContextInfo info 
)
friend

Reads a QScriptContextInfo from the specified stream into the given info.

Since
4.4

Definition at line 528 of file qscriptcontextinfo.cpp.

529 {
530  if (!info.d_ptr) {
531  info.d_ptr = new QScriptContextInfoPrivate();
532  }
533 
534  in >> info.d_ptr->scriptId;
535 
536  qint32 line;
537  in >> line;
538  info.d_ptr->lineNumber = line;
539 
540  qint32 column;
541  in >> column;
542  info.d_ptr->columnNumber = column;
543 
544  quint32 ftype;
545  in >> ftype;
547 
548  qint32 startLine;
549  in >> startLine;
550  info.d_ptr->functionStartLineNumber = startLine;
551 
552  qint32 endLine;
553  in >> endLine;
554  info.d_ptr->functionEndLineNumber = endLine;
555 
556  qint32 metaIndex;
557  in >> metaIndex;
558  info.d_ptr->functionMetaIndex = metaIndex;
559 
560  in >> info.d_ptr->fileName;
561  in >> info.d_ptr->functionName;
562  in >> info.d_ptr->parameterNames;
563 
564  return in;
565 }
int qint32
Definition: qglobal.h:937
FunctionType
This enum specifies the type of function being called.
QExplicitlySharedDataPointer< QScriptContextInfoPrivate > d_ptr
QScriptContextInfo::FunctionType functionType
unsigned int quint32
Definition: qglobal.h:938

Properties

◆ d_ptr

QExplicitlySharedDataPointer<QScriptContextInfoPrivate> QScriptContextInfo::d_ptr
private

Definition at line 90 of file qscriptcontextinfo.h.

Referenced by operator=(), operator>>(), and QScriptContextInfo().


The documentation for this class was generated from the following files: