Qt 4.8
Public Types | Public Slots | Public Functions | Static Public Functions | Properties | List of all members
QDeclarativeInclude Class Reference

#include <qdeclarativeinclude_p.h>

Inheritance diagram for QDeclarativeInclude:
QObject

Public Types

enum  Status { Ok = 0, Loading = 1, NetworkError = 2, Exception = 3 }
 

Public Slots

void finished ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

QScriptValue callback () const
 
 QDeclarativeInclude (const QUrl &, QDeclarativeEngine *, QScriptContext *ctxt)
 
QScriptValue result () const
 
void setCallback (const QScriptValue &)
 
 ~QDeclarativeInclude ()
 
- 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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static void callback (QScriptEngine *, QScriptValue &callback, QScriptValue &status)
 
static QScriptValue include (QScriptContext *ctxt, QScriptEngine *engine)
 
static QScriptValue resultValue (QScriptEngine *, Status status=Loading)
 
static QScriptValue worker_include (QScriptContext *ctxt, QScriptEngine *engine)
 
- 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)
 

Properties

QScriptValue m_callback
 
QDeclarativeGuardedContextData m_context
 
QDeclarativeEnginem_engine
 
QNetworkAccessManagerm_network
 
int m_redirectCount
 
QDeclarativeGuard< QNetworkReplym_reply
 
QScriptValue m_result
 
QScriptValue m_scope [2]
 
QScriptEnginem_scriptEngine
 
QUrl m_url
 

Additional Inherited Members

- 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...
 
- 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...
 
QObjectsender () 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< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 70 of file qdeclarativeinclude_p.h.

Enumerations

◆ Status

Enumerator
Ok 
Loading 
NetworkError 
Exception 

Definition at line 74 of file qdeclarativeinclude_p.h.

Constructors and Destructors

◆ QDeclarativeInclude()

QDeclarativeInclude::QDeclarativeInclude ( const QUrl url,
QDeclarativeEngine engine,
QScriptContext ctxt 
)

Definition at line 54 of file qdeclarativeinclude.cpp.

Referenced by include().

57 : QObject(engine), m_engine(engine), m_network(0), m_reply(0), m_url(url), m_redirectCount(0)
58 {
61 
64 
67 
69 
70  QNetworkRequest request;
71  request.setUrl(url);
72 
73  m_reply = m_network->get(request);
75 }
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
void setUrl(const QUrl &url)
Sets the URL this network request is referring to to be url.
virtual QNetworkAccessManager * networkAccessManager()
#define SLOT(a)
Definition: qobjectdefs.h:226
QDeclarativeGuard< QNetworkReply > m_reply
QDeclarativeContextData * contextFromValue(const QScriptValue &)
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeScriptEngine * get(QScriptEngine *e)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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 rece...
Definition: qobject.cpp:2580
QDeclarativeGuardedContextData m_context
QDeclarativeEngine * m_engine
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
static QScriptValue resultValue(QScriptEngine *, Status status=Loading)
QScriptEngine * m_scriptEngine
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
static QScriptValue scopeChainValue(QScriptContext *, int index)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QNetworkAccessManager * m_network
QDeclarativeContextScriptClass * contextClass

◆ ~QDeclarativeInclude()

QDeclarativeInclude::~QDeclarativeInclude ( )

Definition at line 77 of file qdeclarativeinclude.cpp.

78 {
79  delete m_reply;
80 }
QDeclarativeGuard< QNetworkReply > m_reply

Functions

◆ callback() [1/2]

QScriptValue QDeclarativeInclude::callback ( ) const

Definition at line 104 of file qdeclarativeinclude.cpp.

Referenced by finished(), include(), and worker_include().

105 {
106  return m_callback;
107 }

◆ callback() [2/2]

void QDeclarativeInclude::callback ( QScriptEngine engine,
QScriptValue callback,
QScriptValue status 
)
static

Definition at line 166 of file qdeclarativeinclude.cpp.

167 {
168  if (callback.isValid()) {
169  QScriptValue args = engine->newArray(1);
170  args.setProperty(0, status);
171  callback.call(QScriptValue(), args);
172  }
173 }
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue call(const QScriptValue &thisObject=QScriptValue(), const QScriptValueList &args=QScriptValueList())
Calls this QScriptValue as a function, using thisObject as the `this&#39; object in the function call...
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.

◆ finished

void QDeclarativeInclude::finished ( )
slot

Definition at line 110 of file qdeclarativeinclude.cpp.

Referenced by QDeclarativeInclude().

111 {
112  m_redirectCount++;
113 
116  if (redirect.isValid()) {
117  m_url = m_url.resolved(redirect.toUrl());
118  delete m_reply;
119 
120  QNetworkRequest request;
121  request.setUrl(m_url);
122 
123  m_reply = m_network->get(request);
125  return;
126  }
127  }
128 
131 
133 
134  QString code = QString::fromUtf8(data);
135 
136  QString urlString = m_url.toString();
138  scriptContext->pushScope(ep->contextClass->newUrlContext(m_context, 0, urlString));
139  scriptContext->pushScope(m_scope[0]);
140 
141  scriptContext->pushScope(m_scope[1]);
142  scriptContext->setActivationObject(m_scope[1]);
144 
145  m_scriptEngine->evaluate(code, urlString, 1);
146 
148 
153  } else {
155  }
156  } else {
158  }
159 
161 
162  disconnect();
163  deleteLater();
164 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QScriptContext class represents a Qt Script function invocation.
QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &)
void setUrl(const QUrl &url)
Sets the URL this network request is referring to to be url.
NetworkError error() const
Returns the error that was found during the processing of this request.
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
QDeclarativeGuard< QNetworkReply > m_reply
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void popContext()
Pops the current execution context and restores the previous one.
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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 rece...
Definition: qobject.cpp:2580
QDeclarativeGuardedContextData m_context
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QDeclarativeEngine * m_engine
static const char * data(const QByteArray &arr)
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
QScriptValue callback() const
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.
Definition: qobject.cpp:2895
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
QScriptEngine * m_scriptEngine
#define INCLUDE_MAXIMUM_REDIRECT_RECURSION
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
void clearExceptions()
Clears any uncaught exceptions in this engine.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...
QNetworkAccessManager * m_network
QDeclarativeContextScriptClass * contextClass

◆ include()

QScriptValue QDeclarativeInclude::include ( QScriptContext ctxt,
QScriptEngine engine 
)
static

Definition at line 178 of file qdeclarativeinclude.cpp.

Referenced by QDeclarativeScriptEngine::QDeclarativeScriptEngine().

179 {
180  if (ctxt->argumentCount() == 0)
181  return engine->undefinedValue();
182 
184 
186  if (contextUrl.isEmpty())
187  return ctxt->throwError(QLatin1String("Qt.include(): Can only be called from JavaScript files"));
188 
189  QString urlString = ctxt->argument(0).toString();
190  QUrl url(urlString);
191  if (url.isRelative()) {
192  url = QUrl(contextUrl).resolved(url);
193  urlString = url.toString();
194  }
195 
197 
198  QScriptValue func = ctxt->argument(1);
199  if (!func.isFunction())
200  func = QScriptValue();
201 
203  if (localFile.isEmpty()) {
204  QDeclarativeInclude *i =
206 
207  if (func.isValid())
208  i->setCallback(func);
209 
210  result = i->result();
211  } else {
212 
213  QFile f(localFile);
214  if (f.open(QIODevice::ReadOnly)) {
215  QByteArray data = f.readAll();
216  QString code = QString::fromUtf8(data);
217 
218  QDeclarativeContextData *context =
220 
222  scriptContext->pushScope(ep->contextClass->newUrlContext(context, 0, urlString));
223  scriptContext->pushScope(ep->globalClass->staticGlobalObject());
225  scriptContext->pushScope(scope);
226  scriptContext->setActivationObject(scope);
228 
229  engine->evaluate(code, urlString, 1);
230 
231  engine->popContext();
232 
233  if (engine->hasUncaughtException()) {
234  result = resultValue(engine, Exception);
235  result.setProperty(QLatin1String("exception"), engine->uncaughtException());
236  engine->clearExceptions();
237  } else {
238  result = resultValue(engine, Ok);
239  }
240  callback(engine, func, result);
241  } else {
242  result = resultValue(engine, NetworkError);
243  callback(engine, func, result);
244  }
245  }
246 
247  return result;
248 }
static QString urlToLocalFileOrQrc(const QUrl &url)
The QScriptContext class represents a Qt Script function invocation.
QScriptValue newUrlContext(QDeclarativeContextData *, QObject *, const QString &)
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
static QDeclarativeEngine * getEngine(QScriptEngine *e)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QScriptValue throwError(Error error, const QString &text)
Throws an error with the given text.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QDeclarativeGlobalScriptClass * globalClass
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void popContext()
Pops the current execution context and restores the previous one.
QDeclarativeContextData * contextFromValue(const QScriptValue &)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
const QScriptValue & staticGlobalObject() const
void setCallback(const QScriptValue &)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QScriptValue result() const
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
static QScriptValue resultValue(QScriptEngine *, Status status=Loading)
QScriptValue callback() const
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QDeclarativeInclude(const QUrl &, QDeclarativeEngine *, QScriptContext *ctxt)
static QScriptValue scopeChainValue(QScriptContext *, int index)
void clearExceptions()
Clears any uncaught exceptions in this engine.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
bool isValid() const
Returns true if this QScriptValue is valid; otherwise returns false.
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...
QDeclarativeContextScriptClass * contextClass

◆ result()

QScriptValue QDeclarativeInclude::result ( ) const

Definition at line 94 of file qdeclarativeinclude.cpp.

Referenced by include(), resultValue(), and worker_include().

95 {
96  return m_result;
97 }

◆ resultValue()

QScriptValue QDeclarativeInclude::resultValue ( QScriptEngine engine,
Status  status = Loading 
)
static

Definition at line 82 of file qdeclarativeinclude.cpp.

Referenced by include(), QDeclarativeInclude(), and worker_include().

83 {
84  QScriptValue result = engine->newObject();
85  result.setProperty(QLatin1String("OK"), QScriptValue(engine, Ok));
86  result.setProperty(QLatin1String("LOADING"), QScriptValue(engine, Loading));
87  result.setProperty(QLatin1String("NETWORK_ERROR"), QScriptValue(engine, NetworkError));
88  result.setProperty(QLatin1String("EXCEPTION"), QScriptValue(engine, Exception));
89 
90  result.setProperty(QLatin1String("status"), QScriptValue(engine, status));
91  return result;
92 }
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QScriptValue newObject()
Creates a QtScript object of class Object.
QScriptValue result() const
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ setCallback()

void QDeclarativeInclude::setCallback ( const QScriptValue c)

Definition at line 99 of file qdeclarativeinclude.cpp.

Referenced by include().

100 {
101  m_callback = c;
102 }
unsigned char c[8]
Definition: qnumeric_p.h:62

◆ worker_include()

QScriptValue QDeclarativeInclude::worker_include ( QScriptContext ctxt,
QScriptEngine engine 
)
static

Definition at line 250 of file qdeclarativeinclude.cpp.

Referenced by QDeclarativeScriptEngine::QDeclarativeScriptEngine().

251 {
252  if (ctxt->argumentCount() == 0)
253  return engine->undefinedValue();
254 
255  QString urlString = ctxt->argument(0).toString();
256  QUrl url(ctxt->argument(0).toString());
257  if (url.isRelative()) {
259  Q_ASSERT(!contextUrl.isEmpty());
260 
261  url = QUrl(contextUrl).resolved(url);
262  urlString = url.toString();
263  }
264 
266 
267  QScriptValue func = ctxt->argument(1);
268  if (!func.isFunction())
269  func = QScriptValue();
270 
272  if (!localFile.isEmpty()) {
273 
274  QFile f(localFile);
275  if (f.open(QIODevice::ReadOnly)) {
276  QByteArray data = f.readAll();
277  QString code = QString::fromUtf8(data);
278 
280  QScriptValue urlContext = engine->newObject();
281  urlContext.setData(QScriptValue(engine, urlString));
282  scriptContext->pushScope(urlContext);
283 
285  scriptContext->pushScope(scope);
286  scriptContext->setActivationObject(scope);
288 
289  engine->evaluate(code, urlString, 1);
290 
291  engine->popContext();
292 
293  if (engine->hasUncaughtException()) {
294  result = resultValue(engine, Exception);
295  result.setProperty(QLatin1String("exception"), engine->uncaughtException());
296  engine->clearExceptions();
297  } else {
298  result = resultValue(engine, Ok);
299  }
300  callback(engine, func, result);
301  } else {
302  result = resultValue(engine, NetworkError);
303  callback(engine, func, result);
304  }
305  }
306 
307  return result;
308 }
static QString urlToLocalFileOrQrc(const QUrl &url)
The QScriptContext class represents a Qt Script function invocation.
QScriptValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void popContext()
Pops the current execution context and restores the previous one.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
static const char * data(const QByteArray &arr)
QScriptValue newObject()
Creates a QtScript object of class Object.
QScriptValue result() const
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
static QScriptValue resultValue(QScriptEngine *, Status status=Loading)
QScriptValue callback() const
QScriptValue data() const
Returns the internal data of this QScriptValue object.
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static QScriptValue scopeChainValue(QScriptContext *, int index)
void clearExceptions()
Clears any uncaught exceptions in this engine.
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
void pushScope(const QScriptValue &object)
Adds the given object to the front of this context&#39;s scope chain.
bool hasUncaughtException() const
Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false...
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue uncaughtException() const
Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception...
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.

Properties

◆ m_callback

QScriptValue QDeclarativeInclude::m_callback
private

Definition at line 106 of file qdeclarativeinclude_p.h.

Referenced by callback(), finished(), and setCallback().

◆ m_context

QDeclarativeGuardedContextData QDeclarativeInclude::m_context
private

Definition at line 108 of file qdeclarativeinclude_p.h.

Referenced by finished(), and QDeclarativeInclude().

◆ m_engine

QDeclarativeEngine* QDeclarativeInclude::m_engine
private

Definition at line 99 of file qdeclarativeinclude_p.h.

Referenced by finished().

◆ m_network

QNetworkAccessManager* QDeclarativeInclude::m_network
private

Definition at line 101 of file qdeclarativeinclude_p.h.

Referenced by finished(), and QDeclarativeInclude().

◆ m_redirectCount

int QDeclarativeInclude::m_redirectCount
private

Definition at line 105 of file qdeclarativeinclude_p.h.

Referenced by finished().

◆ m_reply

QDeclarativeGuard<QNetworkReply> QDeclarativeInclude::m_reply
private

Definition at line 102 of file qdeclarativeinclude_p.h.

Referenced by finished(), QDeclarativeInclude(), and ~QDeclarativeInclude().

◆ m_result

QScriptValue QDeclarativeInclude::m_result
private

Definition at line 107 of file qdeclarativeinclude_p.h.

Referenced by finished(), QDeclarativeInclude(), and result().

◆ m_scope

QScriptValue QDeclarativeInclude::m_scope[2]
private

Definition at line 109 of file qdeclarativeinclude_p.h.

Referenced by finished(), and QDeclarativeInclude().

◆ m_scriptEngine

QScriptEngine* QDeclarativeInclude::m_scriptEngine
private

Definition at line 100 of file qdeclarativeinclude_p.h.

Referenced by finished(), and QDeclarativeInclude().

◆ m_url

QUrl QDeclarativeInclude::m_url
private

Definition at line 104 of file qdeclarativeinclude_p.h.

Referenced by finished().


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