Qt 4.8
qdeclarativeworkerscript.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "private/qdeclarativeworkerscript_p.h"
43 #include "private/qdeclarativelistmodel_p.h"
44 #include "private/qdeclarativelistmodelworkeragent_p.h"
45 #include "private/qdeclarativeengine_p.h"
46 #include "private/qdeclarativeexpression_p.h"
47 
48 #include <QtCore/qcoreevent.h>
49 #include <QtCore/qcoreapplication.h>
50 #include <QtCore/qdebug.h>
51 #include <QtScript/qscriptengine.h>
52 #include <QtCore/qmutex.h>
53 #include <QtCore/qwaitcondition.h>
54 #include <QtScript/qscriptvalueiterator.h>
55 #include <QtCore/qfile.h>
56 #include <QtCore/qdatetime.h>
57 #include <QtNetwork/qnetworkaccessmanager.h>
58 #include <QtDeclarative/qdeclarativeinfo.h>
60 
61 
63 
64 class WorkerDataEvent : public QEvent
65 {
66 public:
68 
70  virtual ~WorkerDataEvent();
71 
72  int workerId() const;
73  QVariant data() const;
74 
75 private:
76  int m_id;
78 };
79 
80 class WorkerLoadEvent : public QEvent
81 {
82 public:
83  enum Type { WorkerLoad = WorkerDataEvent::WorkerData + 1 };
84 
85  WorkerLoadEvent(int workerId, const QUrl &url);
86 
87  int workerId() const;
88  QUrl url() const;
89 
90 private:
91  int m_id;
93 };
94 
95 class WorkerRemoveEvent : public QEvent
96 {
97 public:
98  enum Type { WorkerRemove = WorkerLoadEvent::WorkerLoad + 1 };
99 
101 
102  int workerId() const;
103 
104 private:
105  int m_id;
106 };
107 
108 class WorkerErrorEvent : public QEvent
109 {
110 public:
111  enum Type { WorkerError = WorkerRemoveEvent::WorkerRemove + 1 };
112 
114 
115  QDeclarativeError error() const;
116 
117 private:
119 };
120 
122 {
123  Q_OBJECT
124 public:
126  WorkerDestroyEvent = QEvent::User + 100
127  };
128 
130 
132  {
134  ~ScriptEngine() { delete accessManager; }
137 
139  if (!accessManager) {
141  accessManager = p->qmlengine->networkAccessManagerFactory()->create(this);
142  } else {
143  accessManager = new QNetworkAccessManager(this);
144  }
145  }
146  return accessManager;
147  }
148  };
151  return static_cast<ScriptEngine *>(e)->p;
152  }
153 
155 
158 
159  struct WorkerScript {
160  WorkerScript();
161 
162  int id;
167 
169  };
170 
172  QScriptValue getWorker(int);
173 
174  int m_nextId;
175 
176  static QVariant scriptValueToVariant(const QScriptValue &);
177  static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *);
178 
179  static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine);
180  static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine);
181 
182 signals:
183  void stopThread();
184 
185 protected:
186  virtual bool event(QEvent *);
187 
188 private:
189  void processMessage(int, const QVariant &);
190  void processLoad(int, const QUrl &);
191  void reportScriptException(WorkerScript *);
192 };
193 
195 : workerEngine(0), qmlengine(engine), m_nextId(0)
196 {
197 }
198 
200 {
202 
203  int id = ctxt->thisObject().data().toVariant().toInt();
204 
205  WorkerScript *script = p->workers.value(id);
206  if (!script)
207  return engine->undefinedValue();
208 
209  if (ctxt->argumentCount() >= 1)
210  script->callback = ctxt->argument(0);
211 
212  return script->callback;
213 }
214 
216 {
217  if (!ctxt->argumentCount())
218  return engine->undefinedValue();
219 
221 
222  int id = ctxt->thisObject().data().toVariant().toInt();
223 
224  WorkerScript *script = p->workers.value(id);
225  if (!script)
226  return engine->undefinedValue();
227 
228  QMutexLocker(&p->m_lock);
229 
230  if (script->owner)
232  new WorkerDataEvent(0, scriptValueToVariant(ctxt->argument(0))));
233 
234  return engine->undefinedValue();
235 }
236 
238 {
240 
241  if (iter == workers.end())
242  return workerEngine->nullValue();
243 
244  WorkerScript *script = *iter;
245  if (!script->initialized) {
246 
247  script->initialized = true;
248  script->object = workerEngine->newObject();
249 
251  api.setData(script->id);
252 
256 
257  script->object.setProperty(QLatin1String("WorkerScript"), api);
258  }
259 
260  return script->object;
261 }
262 
264 {
265  if (event->type() == (QEvent::Type)WorkerDataEvent::WorkerData) {
266  WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
267  processMessage(workerEvent->workerId(), workerEvent->data());
268  return true;
269  } else if (event->type() == (QEvent::Type)WorkerLoadEvent::WorkerLoad) {
270  WorkerLoadEvent *workerEvent = static_cast<WorkerLoadEvent *>(event);
271  processLoad(workerEvent->workerId(), workerEvent->url());
272  return true;
273  } else if (event->type() == (QEvent::Type)WorkerDestroyEvent) {
274  emit stopThread();
275  return true;
276  } else {
277  return QObject::event(event);
278  }
279 }
280 
282 {
283  WorkerScript *script = workers.value(id);
284  if (!script)
285  return;
286 
287  if (script->callback.isFunction()) {
290 
291  script->callback.call(script->object, args);
292 
294  reportScriptException(script);
296  }
297  }
298 }
299 
301 {
302  if (url.isRelative())
303  return;
304 
306 
307  QFile f(fileName);
308  if (f.open(QIODevice::ReadOnly)) {
309  QByteArray data = f.readAll();
310  QString sourceCode = QString::fromUtf8(data);
311 
312  QScriptValue activation = getWorker(id);
313 
315  QScriptValue urlContext = workerEngine->newObject();
316  urlContext.setData(QScriptValue(workerEngine, url.toString()));
317  ctxt->pushScope(urlContext);
318  ctxt->pushScope(activation);
319  ctxt->setActivationObject(activation);
321 
322  workerEngine->baseUrl = url;
323  workerEngine->evaluate(sourceCode);
324 
325  WorkerScript *script = workers.value(id);
326  if (script) {
327  script->source = url;
329  reportScriptException(script);
331  }
332  }
333 
335  } else {
336  qWarning().nospace() << "WorkerScript: Cannot find source file " << url.toString();
337  }
338 }
339 
341 {
342  if (!script || !workerEngine->hasUncaughtException())
343  return;
344 
347  error.setUrl(script->source);
348 
350 
351  QMutexLocker(&p->m_lock);
352  if (script->owner)
354 }
355 
357 {
358  if (value.isBool()) {
359  return QVariant(value.toBool());
360  } else if (value.isString()) {
361  return QVariant(value.toString());
362  } else if (value.isNumber()) {
363  return QVariant((qreal)value.toNumber());
364  } else if (value.isDate()) {
365  return QVariant(value.toDateTime());
366 #ifndef QT_NO_REGEXP
367  } else if (value.isRegExp()) {
368  return QVariant(value.toRegExp());
369 #endif
370  } else if (value.isArray()) {
371  QVariantList list;
372 
373  quint32 length = (quint32)value.property(QLatin1String("length")).toNumber();
374 
375  for (quint32 ii = 0; ii < length; ++ii) {
376  QVariant v = scriptValueToVariant(value.property(ii));
377  list << v;
378  }
379 
380  return QVariant(list);
381  } else if (value.isQObject()) {
383  if (lm) {
385  if (agent) {
387  return QVariant::fromValue(v);
388  } else {
389  return QVariant();
390  }
391  } else {
392  // No other QObject's are allowed to be sent
393  return QVariant();
394  }
395  } else if (value.isObject()) {
397 
398  QScriptValueIterator iter(value);
399 
400  while (iter.hasNext()) {
401  iter.next();
402  hash.insert(iter.name(), scriptValueToVariant(iter.value()));
403  }
404 
405  return QVariant(hash);
406  }
407 
408  return QVariant();
409 
410 }
411 
413 {
414  if (value.userType() == QVariant::Bool) {
415  return QScriptValue(value.toBool());
416  } else if (value.userType() == QVariant::String) {
417  return QScriptValue(value.toString());
418  } else if (value.userType() == QMetaType::QReal) {
419  return QScriptValue(value.toReal());
420  } else if (value.userType() == QVariant::DateTime) {
421  return engine->newDate(value.toDateTime());
422 #ifndef QT_NO_REGEXP
423  } else if (value.userType() == QVariant::RegExp) {
424  return engine->newRegExp(value.toRegExp());
425 #endif
426  } else if (value.userType() == qMetaTypeId<QDeclarativeListModelWorkerAgent::VariantRef>()) {
428  if (vr.a->scriptEngine() == 0)
429  vr.a->setScriptEngine(engine);
430  else if (vr.a->scriptEngine() != engine)
431  return engine->nullValue();
432  QScriptValue o = engine->newQObject(vr.a);
433  o.setData(engine->newVariant(value)); // Keeps the agent ref so that it is cleaned up on gc
434  return o;
435  } else if (value.userType() == QMetaType::QVariantList) {
436  QVariantList list = qvariant_cast<QVariantList>(value);
437  QScriptValue rv = engine->newArray(list.count());
438 
439  for (quint32 ii = 0; ii < quint32(list.count()); ++ii)
440  rv.setProperty(ii, variantToScriptValue(list.at(ii), engine));
441 
442  return rv;
443  } else if (value.userType() == QMetaType::QVariantHash) {
444 
446 
447  QScriptValue rv = engine->newObject();
448 
449  for (QVariantHash::ConstIterator iter = hash.begin(); iter != hash.end(); ++iter)
450  rv.setProperty(iter.key(), variantToScriptValue(iter.value(), engine));
451 
452  return rv;
453  } else {
454  return engine->nullValue();
455  }
456 }
457 
459 : QEvent((QEvent::Type)WorkerData), m_id(workerId), m_data(data)
460 {
461 }
462 
464 {
465 }
466 
468 {
469  return m_id;
470 }
471 
473 {
474  return m_data;
475 }
476 
478 : QEvent((QEvent::Type)WorkerLoad), m_id(workerId), m_url(url)
479 {
480 }
481 
483 {
484  return m_id;
485 }
486 
488 {
489  return m_url;
490 }
491 
493 : QEvent((QEvent::Type)WorkerRemove), m_id(workerId)
494 {
495 }
496 
498 {
499  return m_id;
500 }
501 
503 : QEvent((QEvent::Type)WorkerError), m_error(error)
504 {
505 }
506 
508 {
509  return m_error;
510 }
511 
513 : QThread(parent), d(new QDeclarativeWorkerScriptEnginePrivate(parent))
514 {
515  d->m_lock.lock();
516  connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection);
518  d->m_wait.wait(&d->m_lock);
519  d->moveToThread(this);
520  d->m_lock.unlock();
521 }
522 
524 {
525  d->m_lock.lock();
526  qDeleteAll(d->workers);
527  d->workers.clear();
529  d->m_lock.unlock();
530 
531  wait();
532  d->deleteLater();
533 }
534 
536 : id(-1), initialized(false), owner(0)
537 {
538 }
539 
541 {
543  script->id = d->m_nextId++;
544  script->owner = owner;
545 
546  d->m_lock.lock();
547  d->workers.insert(script->id, script);
548  d->m_lock.unlock();
549 
550  return script->id;
551 }
552 
554 {
556 }
557 
559 {
561 }
562 
564 {
566 }
567 
569 {
570  d->m_lock.lock();
571 
573 
574  d->m_wait.wakeAll();
575 
576  d->m_lock.unlock();
577 
578  exec();
579 
580  delete d->workerEngine; d->workerEngine = 0;
581 }
582 
583 
630 : QObject(parent), m_engine(0), m_scriptId(-1), m_componentComplete(true)
631 {
632 }
633 
635 {
637 }
638 
649 {
650  return m_source;
651 }
652 
654 {
655  if (m_source == source)
656  return;
657 
658  m_source = source;
659 
660  if (engine())
662 
664 }
665 
687 {
688  if (!engine()) {
689  qWarning("QDeclarativeWorkerScript: Attempt to send message before WorkerScript establishment");
690  return;
691  }
692 
694 }
695 
697 {
698  m_componentComplete = false;
699 }
700 
702 {
703  if (m_engine) return m_engine;
704  if (m_componentComplete) {
706  if (!engine) {
707  qWarning("QDeclarativeWorkerScript: engine() called without qmlEngine() set");
708  return 0;
709  }
710 
713 
714  if (m_source.isValid())
716 
717  return m_engine;
718  }
719  return 0;
720 }
721 
723 {
724  m_componentComplete = true;
725  engine(); // Get it started now.
726 }
727 
739 {
740  if (event->type() == (QEvent::Type)WorkerDataEvent::WorkerData) {
742  if (engine) {
744  WorkerDataEvent *workerEvent = static_cast<WorkerDataEvent *>(event);
745  QScriptValue value =
747  emit message(value);
748  }
749  return true;
750  } else if (event->type() == (QEvent::Type)WorkerErrorEvent::WorkerError) {
751  WorkerErrorEvent *workerEvent = static_cast<WorkerErrorEvent *>(event);
752  QDeclarativeEnginePrivate::warning(qmlEngine(this), workerEvent->error());
753  return true;
754  } else {
755  return QObject::event(event);
756  }
757 }
758 
760 
761 #include <qdeclarativeworkerscript.moc>
762 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
WorkerLoadEvent(int workerId, const QUrl &url)
static QString urlToLocalFileOrQrc(const QUrl &url)
static QScriptEngine * getScriptEngine(QDeclarativeEngine *e)
double d
Definition: qnumeric_p.h:62
The QScriptContext class represents a Qt Script function invocation.
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
virtual void componentComplete()
Invoked after the root component that caused this instantiation has completed construction.
virtual QNetworkAccessManager * create(QObject *parent)=0
Creates and returns a network access manager with the specified parent.
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...
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QDeclarativeWorkerScriptEngine * m_engine
void sendMessage(const QScriptValue &)
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303
QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *eng)
double qreal
Definition: qglobal.h:1193
QRegExp toRegExp() const
Returns the variant as a QRegExp if the variant has type() RegExp ; otherwise returns an empty QRegEx...
Definition: qvariant.cpp:2562
QDeclarativeWorkerScriptEngine(QDeclarativeEngine *parent=0)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
EventRef event
bool isBool() const
Returns true if this QScriptValue is of the primitive type Boolean; otherwise returns false...
bool isFunction() const
Returns true if this QScriptValue is a function; otherwise returns false.
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QDateTime toDateTime() const
Returns a QDateTime representation of this value, in local time.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine)
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
#define error(msg)
QDeclarativeWorkerScriptEngine * engine()
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define SLOT(a)
Definition: qobjectdefs.h:226
const_iterator ConstIterator
Qt-style synonym for QHash::const_iterator.
Definition: qhash.h:474
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
QString name() const
Returns the name of the last property that was jumped over using next() or previous().
int registerWorkerScript(QDeclarativeWorkerScript *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QScriptValue newRegExp(const QRegExp &regexp)
Creates a QtScript object of class RegExp with the given regexp.
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void popContext()
Pops the current execution context and restores the previous one.
virtual bool event(QEvent *)
This handler is called when a message msg is received from a worker script in another thread through ...
QObject * toQObject() const
If this QScriptValue is a QObject, returns the QObject pointer that the QScriptValue represents; othe...
virtual void run()
The starting point for the thread.
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
T * qobject_cast(QObject *object)
Definition: qobject.h:375
static QWidget * owner
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QDeclarativeError error() const
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
virtual void classBegin()
Invoked after class creation, but before any properties have been set.
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &)
static QScriptValue variantToScriptValue(const QVariant &, QScriptEngine *)
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
void quit()
Tells the thread&#39;s event loop to exit with return code 0 (success).
Definition: qthread.cpp:614
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
WorkerDataEvent(int workerId, const QVariant &data)
void setActivationObject(const QScriptValue &activation)
Sets the activation object of this QScriptContext to be the given activation.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QUrl source
This holds the url of the JavaScript file that implements the WorkerScript.
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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
static QDeclarativeWorkerScriptEnginePrivate * get(QScriptEngine *e)
bool isString() const
Returns true if this QScriptValue is of the primitive type String; otherwise returns false...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
QDeclarativeWorkerScriptEnginePrivate * d
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
Q_CORE_EXPORT void qWarning(const char *,...)
bool toBool() const
Returns the boolean value of this QScriptValue, using the conversion rules described in ECMA-262 sect...
static const char * data(const QByteArray &arr)
QDeclarativeListModelWorkerAgent * agent()
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QScriptValue newObject()
Creates a QtScript object of class Object.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
The QDeclarativeError class encapsulates a QML error.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
QDeclarativeNetworkAccessManagerFactory * networkAccessManagerFactory() const
Returns the current QDeclarativeNetworkAccessManagerFactory.
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
void sendMessage(int, const QVariant &)
The QNetworkAccessManager class allows the application to send network requests and receive replies...
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QDeclarativeWorkerScript(QObject *parent=0)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
#define Q_OBJECT
Definition: qobjectdefs.h:157
int argumentCount() const
Returns the number of arguments passed to the function in this invocation.
QScriptValue newQObject(QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
Creates a QtScript object that wraps the given QObject object, using the given ownership.
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
qsreal toNumber() const
Returns the number value of this QScriptValue, as defined in ECMA-262 section 9.3, "ToNumber".
QEventPrivate * d
Definition: qcoreevent.h:315
QScriptValue data() const
Returns the internal data of this QScriptValue object.
bool isNumber() const
Returns true if this QScriptValue is of the primitive type Number; otherwise returns false...
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 QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
The QScriptValueIterator class provides a Java-style iterator for QScriptValue.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
The QDeclarativeEngine class provides an environment for instantiating QML components.
bool isRegExp() const
Returns true if this QScriptValue is an object of the RegExp class; otherwise returns false...
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
QScriptValue value() const
Returns the value of the last property that was jumped over using next() or previous().
unsigned int quint32
Definition: qglobal.h:938
WorkerErrorEvent(const QDeclarativeError &error)
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464
QRegExp toRegExp() const
Returns the QRegExp representation of this value.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
bool isQObject() const
Returns true if this QScriptValue is a QObject; otherwise returns false.
void clearExceptions()
Clears any uncaught exceptions in this engine.
ScriptEngine(QDeclarativeWorkerScriptEnginePrivate *parent)
static void exceptionToError(QScriptEngine *, QDeclarativeError &)
bool isDate() const
Returns true if this QScriptValue is an object of the Date class; otherwise returns false...
QScriptValue newDate(qsreal value)
Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 Jan...
void message(const QScriptValue &messageObject)
static QVariant scriptValueToVariant(const QScriptValue &)
QScriptValue undefinedValue()
Returns a QScriptValue of the primitive type Undefined.
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QScriptValue thisObject() const
Returns the `this&#39; object associated with this QScriptContext.
#define signals
Definition: qobjectdefs.h:69
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...
void warning(const QDeclarativeError &)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine)
static QString fileName(const QString &fileUrl)
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
QDeclarativeWorkerScriptEngine * getWorkerScriptEngine()
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...
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QScriptValue argument(int index) const
Returns the function argument at the given index.
void next()
Advances the iterator by one position.
QScriptValue newVariant(const QVariant &value)
Creates a QtScript object holding the given variant value.
static QScriptContext * pushCleanContext(QScriptEngine *)
Enters a new execution context and returns the associated QScriptContext object.
QScriptValue nullValue()
Returns a QScriptValue of the primitive type Null.
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
bool hasNext() const
Returns true if there is at least one item ahead of the iterator (i.e.
void setData(const QScriptValue &data)
Sets the internal data of this QScriptValue object.