Qt 4.8
qobject.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 QtCore 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 "qobject.h"
43 #include "qobject_p.h"
44 #include "qmetaobject_p.h"
45 
47 #include "qcoreapplication.h"
48 #include "qcoreapplication_p.h"
49 #include "qvariant.h"
50 #include "qmetaobject.h"
51 #include <qregexp.h>
52 #include <qthread.h>
53 #include <private/qthread_p.h>
54 #include <qdebug.h>
55 #include <qhash.h>
56 #include <qpair.h>
57 #include <qset.h>
58 #include <qsemaphore.h>
59 #include <qsharedpointer.h>
60 
61 #include <private/qorderedmutexlocker_p.h>
62 #include <private/qmutexpool_p.h>
63 
64 #include <new>
65 
66 #include <ctype.h>
67 #include <limits.h>
68 
70 
71 static int DIRECT_CONNECTION_ONLY = 0;
72 
73 static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
74 {
75  int *types = new int [typeNames.count() + 1];
76  Q_CHECK_PTR(types);
77  for (int i = 0; i < typeNames.count(); ++i) {
78  const QByteArray typeName = typeNames.at(i);
79  if (typeName.endsWith('*'))
80  types[i] = QMetaType::VoidStar;
81  else
82  types[i] = QMetaType::type(typeName);
83 
84  if (!types[i]) {
85  qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
86  "(Make sure '%s' is registered using qRegisterMetaType().)",
87  typeName.constData(), typeName.constData());
88  delete [] types;
89  return 0;
90  }
91  }
92  types[typeNames.count()] = 0;
93 
94  return types;
95 }
96 
99 
103 static inline QMutex *signalSlotLock(const QObject *o)
104 {
105  if (!signalSlotMutexes) {
106  QMutexPool *mp = new QMutexPool;
107  if (!signalSlotMutexes.testAndSetOrdered(0, mp)) {
108  delete mp;
109  }
110  }
111  return signalSlotMutexes->get(o);
112 }
113 
115 {
116  objectCount.ref();
117 }
118 
120 {
121  if(!objectCount.deref()) {
122  QMutexPool *old = signalSlotMutexes.fetchAndStoreAcquire(0);
123  delete old;
124  }
125 }
126 
130 
132 
134  : threadData(0), connectionLists(0), senders(0), currentSender(0), currentChildBeingDeleted(0)
135 {
136  if (version != QObjectPrivateVersion)
137  qFatal("Cannot mix incompatible Qt library (version 0x%x) with this library (version 0x%x)",
138  version, QObjectPrivateVersion);
139 
140  // QObjectData initialization
141  q_ptr = 0;
142  parent = 0; // no parent yet. It is set by setParent()
143  isWidget = false; // assume not a widget object
144  pendTimer = false; // no timers yet
145  blockSig = false; // not blocking signals
146  wasDeleted = false; // double-delete catcher
147  sendChildEvents = true; // if we should send ChildInsert and ChildRemove events to parent
148  receiveChildEvents = true;
149  postedEvents = 0;
150  extraData = 0;
152  inThreadChangeEvent = false;
153 #ifdef QT_JAMBI_BUILD
154  inEventHandler = false;
155  deleteWatch = 0;
156 #endif
157  metaObject = 0;
158  hasGuards = false;
159 }
160 
162 {
163  if (pendTimer) {
164  // unregister pending timers
167  }
168 
169  if (postedEvents)
171 
172  if (threadData)
173  threadData->deref();
174 
175  delete static_cast<QAbstractDynamicMetaObject*>(metaObject);
176 #ifdef QT_JAMBI_BUILD
177  if (deleteWatch)
178  *deleteWatch = 1;
179 #endif
180 #ifndef QT_NO_USERDATA
181  if (extraData)
183  delete extraData;
184 #endif
185 }
186 
187 
188 #ifdef QT_JAMBI_BUILD
189 int *QObjectPrivate::setDeleteWatch(QObjectPrivate *d, int *w) {
190  int *old = d->deleteWatch;
191  d->deleteWatch = w;
192  return old;
193 }
194 
195 
196 void QObjectPrivate::resetDeleteWatch(QObjectPrivate *d, int *oldWatch, int deleteWatch) {
197  if (!deleteWatch)
198  d->deleteWatch = oldWatch;
199 
200  if (oldWatch)
201  *oldWatch = deleteWatch;
202 }
203 #endif
204 
205 #ifdef QT3_SUPPORT
206 void QObjectPrivate::sendPendingChildInsertedEvents()
207 {
208  Q_Q(QObject);
209  for (int i = 0; i < pendingChildInsertedEvents.size(); ++i) {
210  QObject *c = pendingChildInsertedEvents.at(i).data();
211  if (!c || c->parent() != q)
212  continue;
213  QChildEvent childEvent(QEvent::ChildInserted, c);
214  QCoreApplication::sendEvent(q, &childEvent);
215  }
216  pendingChildInsertedEvents.clear();
217 }
218 
219 #endif
220 
221 
225 static void computeOffsets(const QMetaObject *metaobject, int *signalOffset, int *methodOffset)
226 {
227  *signalOffset = *methodOffset = 0;
228  const QMetaObject *m = metaobject->d.superdata;
229  while (m) {
231  *methodOffset += d->methodCount;
232  *signalOffset += (d->revision >= 4) ? d->signalCount : d->methodCount;
233  /*Before Qt 4.6 (revision 4), the signalCount information was not generated by moc.
234  so for compatibility we consider all the method as slot for old moc output*/
235  m = m->d.superdata;
236  }
237 }
238 
239 /*
240  This vector contains the all connections from an object.
241 
242  Each object may have one vector containing the lists of
243  connections for a given signal. The index in the vector correspond
244  to the signal index. The signal index is the one returned by
245  QObjectPrivate::signalIndex (not QMetaObject::indexOfSignal).
246  Negative index means connections to all signals.
247 
248  This vector is protected by the object mutex (signalSlotMutexes())
249 
250  Each Connection is also part of a 'senders' linked list. The mutex
251  of the receiver must be locked when touching the pointers of this
252  linked list.
253 */
254 class QObjectConnectionListVector : public QVector<QObjectPrivate::ConnectionList>
255 {
256 public:
257  bool orphaned; //the QObject owner of this vector has been destroyed while the vector was inUse
258  bool dirty; //some Connection have been disconnected (their receiver is 0) but not removed from the list yet
259  int inUse; //number of functions that are currently accessing this object or its connections
261 
263  : QVector<QObjectPrivate::ConnectionList>(), orphaned(false), dirty(false), inUse(0)
264  { }
265 
267  {
268  if (at < 0)
269  return allsignals;
271  }
272 };
273 
274 // Used by QAccessibleWidget
275 bool QObjectPrivate::isSender(const QObject *receiver, const char *signal) const
276 {
277  Q_Q(const QObject);
278  int signal_index = signalIndex(signal);
279  if (signal_index < 0)
280  return false;
281  QMutexLocker locker(signalSlotLock(q));
282  if (connectionLists) {
283  if (signal_index < connectionLists->count()) {
285  connectionLists->at(signal_index).first;
286 
287  while (c) {
288  if (c->receiver == receiver)
289  return true;
290  c = c->nextConnectionList;
291  }
292  }
293  }
294  return false;
295 }
296 
297 // Used by QAccessibleWidget
298 QObjectList QObjectPrivate::receiverList(const char *signal) const
299 {
300  Q_Q(const QObject);
301  QObjectList returnValue;
302  int signal_index = signalIndex(signal);
303  if (signal_index < 0)
304  return returnValue;
305  QMutexLocker locker(signalSlotLock(q));
306  if (connectionLists) {
307  if (signal_index < connectionLists->count()) {
308  const QObjectPrivate::Connection *c = connectionLists->at(signal_index).first;
309 
310  while (c) {
311  if (c->receiver)
312  returnValue << c->receiver;
313  c = c->nextConnectionList;
314  }
315  }
316  }
317  return returnValue;
318 }
319 
320 // Used by QAccessibleWidget
322 {
323  QObjectList returnValue;
324  QMutexLocker locker(signalSlotLock(q_func()));
325  for (Connection *c = senders; c; c = c->next)
326  returnValue << c->sender;
327  return returnValue;
328 }
329 
331 {
332  if (!connectionLists)
334  if (signal >= connectionLists->count())
335  connectionLists->resize(signal + 1);
336 
337  ConnectionList &connectionList = (*connectionLists)[signal];
338  if (connectionList.last) {
339  connectionList.last->nextConnectionList = c;
340  } else {
341  connectionList.first = c;
342  }
343  connectionList.last = c;
344 
346 }
347 
349 {
351  // remove broken connections
352  for (int signal = -1; signal < connectionLists->count(); ++signal) {
353  QObjectPrivate::ConnectionList &connectionList =
354  (*connectionLists)[signal];
355 
356  // Set to the last entry in the connection list that was *not*
357  // deleted. This is needed to update the list's last pointer
358  // at the end of the cleanup.
359  QObjectPrivate::Connection *last = 0;
360 
361  QObjectPrivate::Connection **prev = &connectionList.first;
362  QObjectPrivate::Connection *c = *prev;
363  while (c) {
364  if (c->receiver) {
365  last = c;
366  prev = &c->nextConnectionList;
367  c = *prev;
368  } else {
370  *prev = next;
371  delete c;
372  c = next;
373  }
374  }
375 
376  // Correct the connection list's last pointer.
377  // As conectionList.last could equal last, this could be a noop
378  connectionList.last = last;
379  }
380  connectionLists->dirty = false;
381  }
382 }
383 
385 Q_GLOBAL_STATIC(GuardHash, guardHash)
386 Q_GLOBAL_STATIC(QMutex, guardHashLock)
387 
388 
390 void QMetaObject::addGuard(QObject **ptr)
391 {
392  if (!*ptr)
393  return;
394  GuardHash *hash = guardHash();
395  if (!hash) {
396  *ptr = 0;
397  return;
398  }
399  QMutexLocker locker(guardHashLock());
400  QObjectPrivate::get(*ptr)->hasGuards = true;
401  hash->insert(*ptr, ptr);
402 }
403 
407 {
408  if (!*ptr)
409  return;
410  GuardHash *hash = guardHash();
411  /* check that the hash is empty - otherwise we might detach
412  the shared_null hash, which will alloc, which is not nice */
413  if (!hash || hash->isEmpty())
414  return;
415  QMutexLocker locker(guardHashLock());
416  if (!*ptr) //check again, under the lock
417  return;
418  GuardHash::iterator it = hash->find(*ptr);
419  const GuardHash::iterator end = hash->end();
420  bool more = false; //if the QObject has more pointer attached to it.
421  for (; it.key() == *ptr && it != end; ++it) {
422  if (it.value() == ptr) {
423  it = hash->erase(it);
424  if (!more) more = (it != end && it.key() == *ptr);
425  break;
426  }
427  more = true;
428  }
429  if (!more)
430  QObjectPrivate::get(*ptr)->hasGuards = false;
431 }
432 
435 void QMetaObject::changeGuard(QObject **ptr, QObject *o)
436 {
437  GuardHash *hash = guardHash();
438  if (!hash) {
439  *ptr = 0;
440  return;
441  }
442  QMutexLocker locker(guardHashLock());
443  if (o) {
444  hash->insert(o, ptr);
445  QObjectPrivate::get(o)->hasGuards = true;
446  }
447  if (*ptr) {
448  bool more = false; //if the QObject has more pointer attached to it.
449  GuardHash::iterator it = hash->find(*ptr);
450  const GuardHash::iterator end = hash->end();
451  for (; it.key() == *ptr && it != end; ++it) {
452  if (it.value() == ptr) {
453  it = hash->erase(it);
454  if (!more) more = (it != end && it.key() == *ptr);
455  break;
456  }
457  more = true;
458  }
459  if (!more)
460  QObjectPrivate::get(*ptr)->hasGuards = false;
461  }
462  *ptr = o;
463 }
464 
467 void QObjectPrivate::clearGuards(QObject *object)
468 {
469  GuardHash *hash = 0;
470  QMutex *mutex = 0;
471  QT_TRY {
472  hash = guardHash();
473  mutex = guardHashLock();
474  } QT_CATCH(const std::bad_alloc &) {
475  // do nothing in case of OOM - code below is safe
476  }
477 
478  /* check that the hash is empty - otherwise we might detach
479  the shared_null hash, which will alloc, which is not nice */
480  if (hash && !hash->isEmpty()) {
481  QMutexLocker locker(mutex);
482  GuardHash::iterator it = hash->find(object);
483  const GuardHash::iterator end = hash->end();
484  while (it.key() == object && it != end) {
485  *it.value() = 0;
486  it = hash->erase(it);
487  }
488  }
489 }
490 
494  const QObject *sender, int signalId,
495  int nargs, int *types, void **args, QSemaphore *semaphore)
496  : QEvent(MetaCall), sender_(sender), signalId_(signalId),
497  nargs_(nargs), types_(types), args_(args), semaphore_(semaphore),
498  callFunction_(callFunction), method_offset_(method_offset), method_relative_(method_relative)
499 { }
500 
504 {
505  if (types_) {
506  for (int i = 0; i < nargs_; ++i) {
507  if (types_[i] && args_[i])
509  }
510  qFree(types_);
511  qFree(args_);
512  }
513 #ifndef QT_NO_THREAD
514  if (semaphore_)
515  semaphore_->release();
516 #endif
517 }
518 
521 void QMetaCallEvent::placeMetaCall(QObject *object)
522 {
523  if (callFunction_) {
525  } else {
527  }
528 }
529 
700 void *qt_find_obj_child(QObject *parent, const char *type, const QString &name)
701 {
702  QObjectList list = parent->children();
703  if (list.size() == 0) return 0;
704  for (int i = 0; i < list.size(); ++i) {
705  QObject *obj = list.at(i);
706  if (name == obj->objectName() && obj->inherits(type))
707  return obj;
708  }
709  return 0;
710 }
711 
712 
713 /*****************************************************************************
714  QObject member functions
715  *****************************************************************************/
716 
717 // check the constructor's parent thread argument
718 static bool check_parent_thread(QObject *parent,
719  QThreadData *parentThreadData,
720  QThreadData *currentThreadData)
721 {
722  if (parent && parentThreadData != currentThreadData) {
723  QThread *parentThread = parentThreadData->thread;
724  QThread *currentThread = currentThreadData->thread;
725  qWarning("QObject: Cannot create children for a parent that is in a different thread.\n"
726  "(Parent is %s(%p), parent's thread is %s(%p), current thread is %s(%p)",
727  parent->metaObject()->className(),
728  parent,
729  parentThread ? parentThread->metaObject()->className() : "QThread",
730  parentThread,
731  currentThread ? currentThread->metaObject()->className() : "QThread",
732  currentThread);
733  return false;
734  }
735  return true;
736 }
737 
753 QObject::QObject(QObject *parent)
754  : d_ptr(new QObjectPrivate)
755 {
756  Q_D(QObject);
757  d_ptr->q_ptr = this;
758  d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current();
759  d->threadData->ref();
760  if (parent) {
761  QT_TRY {
762  if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData))
763  parent = 0;
764  setParent(parent);
765  } QT_CATCH(...) {
766  d->threadData->deref();
767  QT_RETHROW;
768  }
769  }
770  qt_addObject(this);
771 }
772 
773 #ifdef QT3_SUPPORT
774 
783 QObject::QObject(QObject *parent, const char *name)
784  : d_ptr(new QObjectPrivate)
785 {
786  Q_D(QObject);
787  qt_addObject(d_ptr->q_ptr = this);
788  d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current();
789  d->threadData->ref();
790  if (parent) {
791  if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData))
792  parent = 0;
793  setParent(parent);
794  }
796 }
797 #endif
798 
801 QObject::QObject(QObjectPrivate &dd, QObject *parent)
802  : d_ptr(&dd)
803 {
804  Q_D(QObject);
805  d_ptr->q_ptr = this;
806  d->threadData = (parent && !parent->thread()) ? parent->d_func()->threadData : QThreadData::current();
807  d->threadData->ref();
808  if (parent) {
809  QT_TRY {
810  if (!check_parent_thread(parent, parent ? parent->d_func()->threadData : 0, d->threadData))
811  parent = 0;
812  if (d->isWidget) {
813  if (parent) {
814  d->parent = parent;
815  d->parent->d_func()->children.append(this);
816  }
817  // no events sent here, this is done at the end of the QWidget constructor
818  } else {
819  setParent(parent);
820  }
821  } QT_CATCH(...) {
822  d->threadData->deref();
823  QT_RETHROW;
824  }
825  }
826  qt_addObject(this);
827 }
828 
854 {
855  Q_D(QObject);
856  d->wasDeleted = true;
857  d->blockSig = 0; // unblock signals so we always emit destroyed()
858 
859  if (d->hasGuards && !d->isWidget) {
860  // set all QPointers for this object to zero - note that
861  // ~QWidget() does this for us, so we don't have to do it twice
863  }
864 
865  if (d->sharedRefcount) {
866  if (d->sharedRefcount->strongref > 0) {
867  qWarning("QObject: shared QObject was deleted directly. The program is malformed and may crash.");
868  // but continue deleting, it's too late to stop anyway
869  }
870 
871  // indicate to all QWeakPointers that this QObject has now been deleted
872  d->sharedRefcount->strongref = 0;
873  if (!d->sharedRefcount->weakref.deref())
874  delete d->sharedRefcount;
875  }
876 
877 
878  if (d->isSignalConnected(0)) {
879  QT_TRY {
880  emit destroyed(this);
881  } QT_CATCH(...) {
882  // all the signal/slots connections are still in place - if we don't
883  // quit now, we will crash pretty soon.
884  qWarning("Detected an unexpected exception in ~QObject while emitting destroyed().");
885  QT_RETHROW;
886  }
887  }
888 
889  if (d->declarativeData)
891 
892  // set ref to zero to indicate that this object has been deleted
893  if (d->currentSender != 0)
894  d->currentSender->ref = 0;
895  d->currentSender = 0;
896 
897  if (d->connectionLists || d->senders) {
898  QMutex *signalSlotMutex = signalSlotLock(this);
899  QMutexLocker locker(signalSlotMutex);
900 
901  // disconnect all receivers
902  if (d->connectionLists) {
903  ++d->connectionLists->inUse;
904  int connectionListsCount = d->connectionLists->count();
905  for (int signal = -1; signal < connectionListsCount; ++signal) {
906  QObjectPrivate::ConnectionList &connectionList =
907  (*d->connectionLists)[signal];
908 
909  while (QObjectPrivate::Connection *c = connectionList.first) {
910  if (!c->receiver) {
911  connectionList.first = c->nextConnectionList;
912  delete c;
913  continue;
914  }
915 
916  QMutex *m = signalSlotLock(c->receiver);
917  bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
918 
919  if (c->receiver) {
920  *c->prev = c->next;
921  if (c->next) c->next->prev = c->prev;
922  }
923  if (needToUnlock)
924  m->unlockInline();
925 
926  connectionList.first = c->nextConnectionList;
927  delete c;
928  }
929  }
930 
931  if (!--d->connectionLists->inUse) {
932  delete d->connectionLists;
933  } else {
934  d->connectionLists->orphaned = true;
935  }
936  d->connectionLists = 0;
937  }
938 
939  // disconnect all senders
941  while (node) {
942  QObject *sender = node->sender;
943  QMutex *m = signalSlotLock(sender);
944  node->prev = &node;
945  bool needToUnlock = QOrderedMutexLocker::relock(signalSlotMutex, m);
946  //the node has maybe been removed while the mutex was unlocked in relock?
947  if (!node || node->sender != sender) {
948  m->unlockInline();
949  continue;
950  }
951  node->receiver = 0;
952  QObjectConnectionListVector *senderLists = sender->d_func()->connectionLists;
953  if (senderLists)
954  senderLists->dirty = true;
955 
956  node = node->next;
957  if (needToUnlock)
958  m->unlockInline();
959  }
960  }
961 
962  if (!d->children.isEmpty())
963  d->deleteChildren();
964 
965  qt_removeObject(this);
966 
967  if (d->parent) // remove it from parent object
968  d->setParent_helper(0);
969 
970 #ifdef QT_JAMBI_BUILD
971  if (d->inEventHandler) {
972  qWarning("QObject: Do not delete object, '%s', during its event handler!",
973  objectName().isNull() ? "unnamed" : qPrintable(objectName()));
974  }
975 #endif
976 }
977 
979 {
980  if (argumentTypes != &DIRECT_CONNECTION_ONLY)
981  delete [] static_cast<int *>(argumentTypes);
982 }
983 
984 
1104 {
1105  Q_D(const QObject);
1106  return d->objectName;
1107 }
1108 
1109 /*
1110  Sets the object's name to \a name.
1111 */
1113 {
1114  Q_D(QObject);
1115  bool objectNameChanged = d->declarativeData && d->objectName != name;
1116 
1117  d->objectName = name;
1118 
1119  if (objectNameChanged)
1121 }
1122 
1123 
1124 #ifdef QT3_SUPPORT
1125 
1132 static QObject *qChildHelper(const char *objName, const char *inheritsClass,
1133  bool recursiveSearch, const QObjectList &children)
1134 {
1135  if (children.isEmpty())
1136  return 0;
1137 
1138  bool onlyWidgets = (inheritsClass && qstrcmp(inheritsClass, "QWidget") == 0);
1139  const QLatin1String oName(objName);
1140  for (int i = 0; i < children.size(); ++i) {
1141  QObject *obj = children.at(i);
1142  if (onlyWidgets) {
1143  if (obj->isWidgetType() && (!objName || obj->objectName() == oName))
1144  return obj;
1145  } else if ((!inheritsClass || obj->inherits(inheritsClass))
1146  && (!objName || obj->objectName() == oName))
1147  return obj;
1148  if (recursiveSearch && (obj = qChildHelper(objName, inheritsClass,
1149  recursiveSearch, obj->children())))
1150  return obj;
1151  }
1152  return 0;
1153 }
1154 
1155 
1168 QObject* QObject::child(const char *objName, const char *inheritsClass,
1169  bool recursiveSearch) const
1170 {
1171  Q_D(const QObject);
1172  return qChildHelper(objName, inheritsClass, recursiveSearch, d->children);
1173 }
1174 #endif
1175 
1201 {
1202  switch (e->type()) {
1203  case QEvent::Timer:
1204  timerEvent((QTimerEvent*)e);
1205  break;
1206 
1207 #ifdef QT3_SUPPORT
1208  case QEvent::ChildInsertedRequest:
1209  d_func()->sendPendingChildInsertedEvents();
1210  break;
1211 #endif
1212 
1213  case QEvent::ChildAdded:
1214  case QEvent::ChildPolished:
1215 #ifdef QT3_SUPPORT
1216  case QEvent::ChildInserted:
1217 #endif
1218  case QEvent::ChildRemoved:
1219  childEvent((QChildEvent*)e);
1220  break;
1221 
1223  qDeleteInEventHandler(this);
1224  break;
1225 
1226  case QEvent::MetaCall:
1227  {
1228 #ifdef QT_JAMBI_BUILD
1229  d_func()->inEventHandler = false;
1230 #endif
1231  QMetaCallEvent *mce = static_cast<QMetaCallEvent*>(e);
1232  QObjectPrivate::Sender currentSender;
1233  currentSender.sender = const_cast<QObject*>(mce->sender());
1234  currentSender.signal = mce->signalId();
1235  currentSender.ref = 1;
1236  QObjectPrivate::Sender * const previousSender =
1237  QObjectPrivate::setCurrentSender(this, &currentSender);
1238 #if defined(QT_NO_EXCEPTIONS)
1239  mce->placeMetaCall(this);
1240 #else
1241  QT_TRY {
1242  mce->placeMetaCall(this);
1243  } QT_CATCH(...) {
1244  QObjectPrivate::resetCurrentSender(this, &currentSender, previousSender);
1245  QT_RETHROW;
1246  }
1247 #endif
1248  QObjectPrivate::resetCurrentSender(this, &currentSender, previousSender);
1249  break;
1250  }
1251 
1252  case QEvent::ThreadChange: {
1253  Q_D(QObject);
1254  QThreadData *threadData = d->threadData;
1255  QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher;
1256  if (eventDispatcher) {
1257  QList<QPair<int, int> > timers = eventDispatcher->registeredTimers(this);
1258  if (!timers.isEmpty()) {
1259  // set inThreadChangeEvent to true to tell the dispatcher not to release out timer ids
1260  // back to the pool (since the timer ids are moving to a new thread).
1261  d->inThreadChangeEvent = true;
1262  eventDispatcher->unregisterTimers(this);
1263  d->inThreadChangeEvent = false;
1264  QMetaObject::invokeMethod(this, "_q_reregisterTimers", Qt::QueuedConnection,
1265  Q_ARG(void*, (new QList<QPair<int, int> >(timers))));
1266  }
1267  }
1268  break;
1269  }
1270 
1271  default:
1272  if (e->type() >= QEvent::User) {
1273  customEvent(e);
1274  break;
1275  }
1276  return false;
1277  }
1278  return true;
1279 }
1280 
1295 {
1296 }
1297 
1298 
1333 {
1334 }
1335 
1336 
1346 void QObject::customEvent(QEvent * /* event */)
1347 {
1348 }
1349 
1350 
1351 
1375 bool QObject::eventFilter(QObject * /* watched */, QEvent * /* event */)
1376 {
1377  return false;
1378 }
1379 
1406 bool QObject::blockSignals(bool block)
1407 {
1408  Q_D(QObject);
1409  bool previous = d->blockSig;
1410  d->blockSig = block;
1411  return previous;
1412 }
1413 
1420 {
1421  return d_func()->threadData->thread;
1422 }
1423 
1458 void QObject::moveToThread(QThread *targetThread)
1459 {
1460  Q_D(QObject);
1461 
1462  if (d->threadData->thread == targetThread) {
1463  // object is already in this thread
1464  return;
1465  }
1466 
1467  if (d->parent != 0) {
1468  qWarning("QObject::moveToThread: Cannot move objects with a parent");
1469  return;
1470  }
1471  if (d->isWidget) {
1472  qWarning("QObject::moveToThread: Widgets cannot be moved to a new thread");
1473  return;
1474  }
1475 
1476  QThreadData *currentData = QThreadData::current();
1477  QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : new QThreadData(0);
1478  if (d->threadData->thread == 0 && currentData == targetData) {
1479  // one exception to the rule: we allow moving objects with no thread affinity to the current thread
1480  currentData = d->threadData;
1481  } else if (d->threadData != currentData) {
1482  qWarning("QObject::moveToThread: Current thread (%p) is not the object's thread (%p).\n"
1483  "Cannot move to target thread (%p)\n",
1484  currentData->thread, d->threadData->thread, targetData->thread);
1485 
1486 #ifdef Q_WS_MAC
1487  qWarning("On Mac OS X, you might be loading two sets of Qt binaries into the same process. "
1488  "Check that all plugins are compiled against the right Qt binaries. Export "
1489  "DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.");
1490 #endif
1491 
1492  return;
1493  }
1494 
1495  // prepare to move
1496  d->moveToThread_helper();
1497 
1498  QOrderedMutexLocker locker(&currentData->postEventList.mutex,
1499  &targetData->postEventList.mutex);
1500 
1501  // keep currentData alive (since we've got it locked)
1502  currentData->ref();
1503 
1504  // move the object
1505  d_func()->setThreadData_helper(currentData, targetData);
1506 
1507  locker.unlock();
1508 
1509  // now currentData can commit suicide if it wants to
1510  currentData->deref();
1511 }
1512 
1514 {
1515  Q_Q(QObject);
1518  for (int i = 0; i < children.size(); ++i) {
1519  QObject *child = children.at(i);
1520  child->d_func()->moveToThread_helper();
1521  }
1522 }
1523 
1525 {
1526  Q_Q(QObject);
1527 
1528  // move posted events
1529  int eventsMoved = 0;
1530  for (int i = 0; i < currentData->postEventList.size(); ++i) {
1531  const QPostEvent &pe = currentData->postEventList.at(i);
1532  if (!pe.event)
1533  continue;
1534  if (pe.receiver == q) {
1535  // move this post event to the targetList
1536  targetData->postEventList.addEvent(pe);
1537  const_cast<QPostEvent &>(pe).event = 0;
1538  ++eventsMoved;
1539  }
1540  }
1541  if (eventsMoved > 0 && targetData->eventDispatcher) {
1542  targetData->canWait = false;
1543  targetData->eventDispatcher->wakeUp();
1544  }
1545 
1546  // the current emitting thread shouldn't restore currentSender after calling moveToThread()
1547  if (currentSender)
1548  currentSender->ref = 0;
1549  currentSender = 0;
1550 
1551 #ifdef QT_JAMBI_BUILD
1552  // the current event thread also shouldn't restore the delete watch
1553  inEventHandler = false;
1554 
1555  if (deleteWatch)
1556  *deleteWatch = 1;
1557  deleteWatch = 0;
1558 #endif
1559 
1560  // set new thread data
1561  targetData->ref();
1562  threadData->deref();
1563  threadData = targetData;
1564 
1565  for (int i = 0; i < children.size(); ++i) {
1566  QObject *child = children.at(i);
1567  child->d_func()->setThreadData_helper(currentData, targetData);
1568  }
1569 }
1570 
1572 {
1573  Q_Q(QObject);
1574  QList<QPair<int, int> > *timerList = reinterpret_cast<QList<QPair<int, int> > *>(pointer);
1575  QAbstractEventDispatcher *eventDispatcher = threadData->eventDispatcher;
1576  for (int i = 0; i < timerList->size(); ++i) {
1577  const QPair<int, int> &pair = timerList->at(i);
1578  eventDispatcher->registerTimer(pair.first, pair.second, q);
1579  }
1580  delete timerList;
1581 }
1582 
1583 
1584 //
1585 // The timer flag hasTimer is set when startTimer is called.
1586 // It is not reset when killing the timer because more than
1587 // one timer might be active.
1588 //
1589 
1623 int QObject::startTimer(int interval)
1624 {
1625  Q_D(QObject);
1626 
1627  if (interval < 0) {
1628  qWarning("QObject::startTimer: QTimer cannot have a negative interval");
1629  return 0;
1630  }
1631 
1632  d->pendTimer = true; // set timer flag
1633 
1634  if (!d->threadData->eventDispatcher) {
1635  qWarning("QObject::startTimer: QTimer can only be used with threads started with QThread");
1636  return 0;
1637  }
1638  return d->threadData->eventDispatcher->registerTimer(interval, this);
1639 }
1640 
1651 {
1652  Q_D(QObject);
1653  if (d->threadData->eventDispatcher)
1655 }
1656 
1657 
1689 #ifdef QT3_SUPPORT
1690 static void objSearch(QObjectList &result,
1691  const QObjectList &list,
1692  const char *inheritsClass,
1693  bool onlyWidgets,
1694  const char *objName,
1695  QRegExp *rx,
1696  bool recurse)
1697 {
1698  for (int i = 0; i < list.size(); ++i) {
1699  QObject *obj = list.at(i);
1700  if (!obj)
1701  continue;
1702  bool ok = true;
1703  if (onlyWidgets)
1704  ok = obj->isWidgetType();
1705  else if (inheritsClass && !obj->inherits(inheritsClass))
1706  ok = false;
1707  if (ok) {
1708  if (objName)
1709  ok = (obj->objectName() == QLatin1String(objName));
1710 #ifndef QT_NO_REGEXP
1711  else if (rx)
1712  ok = (rx->indexIn(obj->objectName()) != -1);
1713 #endif
1714  }
1715  if (ok) // match!
1716  result.append(obj);
1717  if (recurse) {
1718  QObjectList clist = obj->children();
1719  if (!clist.isEmpty())
1720  objSearch(result, clist, inheritsClass,
1721  onlyWidgets, objName, rx, recurse);
1722  }
1723  }
1724 }
1725 
1768 QObjectList QObject::queryList(const char *inheritsClass,
1769  const char *objName,
1770  bool regexpMatch,
1771  bool recursiveSearch) const
1772 {
1773  Q_D(const QObject);
1774  QObjectList list;
1775  bool onlyWidgets = (inheritsClass && qstrcmp(inheritsClass, "QWidget") == 0);
1776 #ifndef QT_NO_REGEXP
1777  if (regexpMatch && objName) { // regexp matching
1778  QRegExp rx(QString::fromLatin1(objName));
1779  objSearch(list, d->children, inheritsClass, onlyWidgets, 0, &rx, recursiveSearch);
1780  } else
1781 #endif
1782  {
1783  objSearch(list, d->children, inheritsClass, onlyWidgets, objName, 0, recursiveSearch);
1784  }
1785  return list;
1786 }
1787 #endif
1788 
1900 void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re,
1901  const QMetaObject &mo, QList<void*> *list)
1902 {
1903  if (!parent || !list)
1904  return;
1905  const QObjectList &children = parent->children();
1906  QObject *obj;
1907  for (int i = 0; i < children.size(); ++i) {
1908  obj = children.at(i);
1909  if (mo.cast(obj)) {
1910  if (re) {
1911  if (re->indexIn(obj->objectName()) != -1)
1912  list->append(obj);
1913  } else {
1914  if (name.isNull() || obj->objectName() == name)
1915  list->append(obj);
1916  }
1917  }
1918  qt_qFindChildren_helper(obj, name, re, mo, list);
1919  }
1920 }
1921 
1924 QObject *qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo)
1925 {
1926  if (!parent)
1927  return 0;
1928  const QObjectList &children = parent->children();
1929  QObject *obj;
1930  int i;
1931  for (i = 0; i < children.size(); ++i) {
1932  obj = children.at(i);
1933  if (mo.cast(obj) && (name.isNull() || obj->objectName() == name))
1934  return obj;
1935  }
1936  for (i = 0; i < children.size(); ++i) {
1937  obj = qt_qFindChild_helper(children.at(i), name, mo);
1938  if (obj)
1939  return obj;
1940  }
1941  return 0;
1942 }
1943 
1950 void QObject::setParent(QObject *parent)
1951 {
1952  Q_D(QObject);
1953  Q_ASSERT(!d->isWidget);
1954  d->setParent_helper(parent);
1955 }
1956 
1958 {
1959  const bool reallyWasDeleted = wasDeleted;
1960  wasDeleted = true;
1961  // delete children objects
1962  // don't use qDeleteAll as the destructor of the child might
1963  // delete siblings
1964  for (int i = 0; i < children.count(); ++i) {
1965  currentChildBeingDeleted = children.at(i);
1966  children[i] = 0;
1967  delete currentChildBeingDeleted;
1968  }
1969  children.clear();
1970  currentChildBeingDeleted = 0;
1971  wasDeleted = reallyWasDeleted;
1972 }
1973 
1975 {
1976  Q_Q(QObject);
1977  if (o == parent)
1978  return;
1979  if (parent) {
1980  QObjectPrivate *parentD = parent->d_func();
1981  if (parentD->wasDeleted && wasDeleted
1982  && parentD->currentChildBeingDeleted == q) {
1983  // don't do anything since QObjectPrivate::deleteChildren() already
1984  // cleared our entry in parentD->children.
1985  } else {
1986  const int index = parentD->children.indexOf(q);
1987  if (parentD->wasDeleted) {
1988  parentD->children[index] = 0;
1989  } else {
1990  parentD->children.removeAt(index);
1991  if (sendChildEvents && parentD->receiveChildEvents) {
1993  QCoreApplication::sendEvent(parent, &e);
1994  }
1995  }
1996  }
1997  }
1998  parent = o;
1999  if (parent) {
2000  // object hierarchies are constrained to a single thread
2001  if (threadData != parent->d_func()->threadData) {
2002  qWarning("QObject::setParent: Cannot set parent, new parent is in a different thread");
2003  parent = 0;
2004  return;
2005  }
2006  parent->d_func()->children.append(q);
2007  if(sendChildEvents && parent->d_func()->receiveChildEvents) {
2008  if (!isWidget) {
2010  QCoreApplication::sendEvent(parent, &e);
2011 #ifdef QT3_SUPPORT
2012  if (QCoreApplicationPrivate::useQt3Support) {
2013  if (parent->d_func()->pendingChildInsertedEvents.isEmpty()) {
2015  new QEvent(QEvent::ChildInsertedRequest),
2017  }
2018  parent->d_func()->pendingChildInsertedEvents.append(q);
2019  }
2020 #endif
2021  }
2022  }
2023  }
2024  if (!wasDeleted && declarativeData)
2025  QAbstractDeclarativeData::parentChanged(declarativeData, q, o);
2026 }
2027 
2071 {
2072  Q_D(QObject);
2073  if (!obj)
2074  return;
2075  if (d->threadData != obj->d_func()->threadData) {
2076  qWarning("QObject::installEventFilter(): Cannot filter events for objects in a different thread.");
2077  return;
2078  }
2079 
2080  // clean up unused items in the list
2081  d->eventFilters.removeAll((QObject*)0);
2082  d->eventFilters.removeAll(obj);
2083  d->eventFilters.prepend(obj);
2084 }
2085 
2099 void QObject::removeEventFilter(QObject *obj)
2100 {
2101  Q_D(QObject);
2102  for (int i = 0; i < d->eventFilters.count(); ++i) {
2103  if (d->eventFilters.at(i) == obj)
2104  d->eventFilters[i] = 0;
2105  }
2106 }
2107 
2108 
2146 {
2148 }
2149 
2217 /*****************************************************************************
2218  Signals and slots
2219  *****************************************************************************/
2220 
2221 
2222 const char *qFlagLocation(const char *method)
2223 {
2225  return method;
2226 }
2227 
2228 static int extract_code(const char *member)
2229 {
2230  // extract code, ensure QMETHOD_CODE <= code <= QSIGNAL_CODE
2231  return (((int)(*member) - '0') & 0x3);
2232 }
2233 
2234 static const char * extract_location(const char *member)
2235 {
2236  if (QThreadData::current()->flaggedSignatures.contains(member)) {
2237  // signature includes location information after the first null-terminator
2238  const char *location = member + qstrlen(member) + 1;
2239  if (*location != '\0')
2240  return location;
2241  }
2242  return 0;
2243 }
2244 
2245 static bool check_signal_macro(const QObject *sender, const char *signal,
2246  const char *func, const char *op)
2247 {
2248  int sigcode = extract_code(signal);
2249  if (sigcode != QSIGNAL_CODE) {
2250  if (sigcode == QSLOT_CODE)
2251  qWarning("Object::%s: Attempt to %s non-signal %s::%s",
2252  func, op, sender->metaObject()->className(), signal+1);
2253  else
2254  qWarning("Object::%s: Use the SIGNAL macro to %s %s::%s",
2255  func, op, sender->metaObject()->className(), signal);
2256  return false;
2257  }
2258  return true;
2259 }
2260 
2261 static bool check_method_code(int code, const QObject *object,
2262  const char *method, const char *func)
2263 {
2264  if (code != QSLOT_CODE && code != QSIGNAL_CODE) {
2265  qWarning("Object::%s: Use the SLOT or SIGNAL macro to "
2266  "%s %s::%s", func, func, object->metaObject()->className(), method);
2267  return false;
2268  }
2269  return true;
2270 }
2271 
2272 static void err_method_notfound(const QObject *object,
2273  const char *method, const char *func)
2274 {
2275  const char *type = "method";
2276  switch (extract_code(method)) {
2277  case QSLOT_CODE: type = "slot"; break;
2278  case QSIGNAL_CODE: type = "signal"; break;
2279  }
2280  const char *loc = extract_location(method);
2281  if (strchr(method,')') == 0) // common typing mistake
2282  qWarning("Object::%s: Parentheses expected, %s %s::%s%s%s",
2283  func, type, object->metaObject()->className(), method+1,
2284  loc ? " in ": "", loc ? loc : "");
2285  else
2286  qWarning("Object::%s: No such %s %s::%s%s%s",
2287  func, type, object->metaObject()->className(), method+1,
2288  loc ? " in ": "", loc ? loc : "");
2289 
2290 }
2291 
2292 
2293 static void err_info_about_objects(const char * func,
2294  const QObject * sender,
2295  const QObject * receiver)
2296 {
2297  QString a = sender ? sender->objectName() : QString();
2298  QString b = receiver ? receiver->objectName() : QString();
2299  if (!a.isEmpty())
2300  qWarning("Object::%s: (sender name: '%s')", func, a.toLocal8Bit().data());
2301  if (!b.isEmpty())
2302  qWarning("Object::%s: (receiver name: '%s')", func, b.toLocal8Bit().data());
2303 }
2304 
2327 QObject *QObject::sender() const
2328 {
2329  Q_D(const QObject);
2330 
2331  QMutexLocker locker(signalSlotLock(this));
2332  if (!d->currentSender)
2333  return 0;
2334 
2335  for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) {
2336  if (c->sender == d->currentSender->sender)
2337  return d->currentSender->sender;
2338  }
2339 
2340  return 0;
2341 }
2342 
2369 {
2370  Q_D(const QObject);
2371 
2372  QMutexLocker locker(signalSlotLock(this));
2373  if (!d->currentSender)
2374  return -1;
2375 
2376  for (QObjectPrivate::Connection *c = d->senders; c; c = c->next) {
2377  if (c->sender == d->currentSender->sender)
2378  return d->currentSender->signal;
2379  }
2380 
2381  return -1;
2382 }
2383 
2406 int QObject::receivers(const char *signal) const
2407 {
2408  Q_D(const QObject);
2409  int receivers = 0;
2410  if (signal) {
2411  QByteArray signal_name = QMetaObject::normalizedSignature(signal);
2412  signal = signal_name;
2413 #ifndef QT_NO_DEBUG
2414  if (!check_signal_macro(this, signal, "receivers", "bind"))
2415  return 0;
2416 #endif
2417  signal++; // skip code
2418  int signal_index = d->signalIndex(signal);
2419  if (signal_index < 0) {
2420 #ifndef QT_NO_DEBUG
2421  err_method_notfound(this, signal-1, "receivers");
2422 #endif
2423  return false;
2424  }
2425 
2426  Q_D(const QObject);
2427  QMutexLocker locker(signalSlotLock(this));
2428  if (d->connectionLists) {
2429  if (signal_index < d->connectionLists->count()) {
2430  const QObjectPrivate::Connection *c =
2431  d->connectionLists->at(signal_index).first;
2432  while (c) {
2433  receivers += c->receiver ? 1 : 0;
2434  c = c->nextConnectionList;
2435  }
2436  }
2437  }
2438  }
2439  return receivers;
2440 }
2441 
2468 void QMetaObjectPrivate::memberIndexes(const QObject *obj,
2469  const QMetaMethod &member,
2470  int *signalIndex, int *methodIndex)
2471 {
2472  *signalIndex = -1;
2473  *methodIndex = -1;
2474  if (!obj || !member.mobj)
2475  return;
2476  const QMetaObject *m = obj->metaObject();
2477  // Check that member is member of obj class
2478  while (m != 0 && m != member.mobj)
2479  m = m->d.superdata;
2480  if (!m)
2481  return;
2482  *signalIndex = *methodIndex = (member.handle - get(member.mobj)->methodData)/5;
2483 
2484  int signalOffset;
2485  int methodOffset;
2486  computeOffsets(m, &signalOffset, &methodOffset);
2487 
2488  *methodIndex += methodOffset;
2489  if (member.methodType() == QMetaMethod::Signal) {
2490  *signalIndex = originalClone(m, *signalIndex);
2491  *signalIndex += signalOffset;
2492  } else {
2493  *signalIndex = -1;
2494  }
2495 }
2496 
2497 static inline void check_and_warn_compat(const QMetaObject *sender, const QMetaMethod &signal,
2498  const QMetaObject *receiver, const QMetaMethod &method)
2499 {
2500  if (signal.attributes() & QMetaMethod::Compatibility) {
2501  if (!(method.attributes() & QMetaMethod::Compatibility))
2502  qWarning("QObject::connect: Connecting from COMPAT signal (%s::%s)",
2503  sender->className(), signal.signature());
2504  } else if ((method.attributes() & QMetaMethod::Compatibility) &&
2505  method.methodType() == QMetaMethod::Signal) {
2506  qWarning("QObject::connect: Connecting from %s::%s to COMPAT slot (%s::%s)",
2507  sender->className(), signal.signature(),
2508  receiver->className(), method.signature());
2509  }
2510 }
2511 
2580 bool QObject::connect(const QObject *sender, const char *signal,
2581  const QObject *receiver, const char *method,
2583 {
2584  {
2585  const void *cbdata[] = { sender, signal, receiver, method, &type };
2587  return true;
2588  }
2589 
2590 #ifndef QT_NO_DEBUG
2591  bool warnCompat = true;
2592 #endif
2593  if (type == Qt::AutoCompatConnection) {
2594  type = Qt::AutoConnection;
2595 #ifndef QT_NO_DEBUG
2596  warnCompat = false;
2597 #endif
2598  }
2599 
2600  if (sender == 0 || receiver == 0 || signal == 0 || method == 0) {
2601  qWarning("QObject::connect: Cannot connect %s::%s to %s::%s",
2602  sender ? sender->metaObject()->className() : "(null)",
2603  (signal && *signal) ? signal+1 : "(null)",
2604  receiver ? receiver->metaObject()->className() : "(null)",
2605  (method && *method) ? method+1 : "(null)");
2606  return false;
2607  }
2608  QByteArray tmp_signal_name;
2609 
2610  if (!check_signal_macro(sender, signal, "connect", "bind"))
2611  return false;
2612  const QMetaObject *smeta = sender->metaObject();
2613  const char *signal_arg = signal;
2614  ++signal; //skip code
2615  int signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
2616  if (signal_index < 0) {
2617  // check for normalized signatures
2618  tmp_signal_name = QMetaObject::normalizedSignature(signal - 1);
2619  signal = tmp_signal_name.constData() + 1;
2620 
2621  smeta = sender->metaObject();
2622  signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
2623  }
2624  if (signal_index < 0) {
2625  // re-use tmp_signal_name and signal from above
2626 
2627  smeta = sender->metaObject();
2628  signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true);
2629  }
2630  if (signal_index < 0) {
2631  err_method_notfound(sender, signal_arg, "connect");
2632  err_info_about_objects("connect", sender, receiver);
2633  return false;
2634  }
2635  signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index);
2636  int signalOffset, methodOffset;
2637  computeOffsets(smeta, &signalOffset, &methodOffset);
2638  int signal_absolute_index = signal_index + methodOffset;
2639  signal_index += signalOffset;
2640 
2641  QByteArray tmp_method_name;
2642  int membcode = extract_code(method);
2643 
2644  if (!check_method_code(membcode, receiver, method, "connect"))
2645  return false;
2646  const char *method_arg = method;
2647  ++method; // skip code
2648 
2649  const QMetaObject *rmeta = receiver->metaObject();
2650  int method_index_relative = -1;
2651  switch (membcode) {
2652  case QSLOT_CODE:
2653  method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, false);
2654  break;
2655  case QSIGNAL_CODE:
2656  method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, false);
2657  break;
2658  }
2659 
2660  if (method_index_relative < 0) {
2661  // check for normalized methods
2662  tmp_method_name = QMetaObject::normalizedSignature(method);
2663  method = tmp_method_name.constData();
2664 
2665  // rmeta may have been modified above
2666  rmeta = receiver->metaObject();
2667  switch (membcode) {
2668  case QSLOT_CODE:
2669  method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, false);
2670  if (method_index_relative < 0)
2671  method_index_relative = QMetaObjectPrivate::indexOfSlotRelative(&rmeta, method, true);
2672  break;
2673  case QSIGNAL_CODE:
2674  method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, false);
2675  if (method_index_relative < 0)
2676  method_index_relative = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, true);
2677  break;
2678  }
2679  }
2680 
2681  if (method_index_relative < 0) {
2682  err_method_notfound(receiver, method_arg, "connect");
2683  err_info_about_objects("connect", sender, receiver);
2684  return false;
2685  }
2686 
2687  if (!QMetaObject::checkConnectArgs(signal, method)) {
2688  qWarning("QObject::connect: Incompatible sender/receiver arguments"
2689  "\n %s::%s --> %s::%s",
2690  sender->metaObject()->className(), signal,
2691  receiver->metaObject()->className(), method);
2692  return false;
2693  }
2694 
2695  int *types = 0;
2696  if ((type == Qt::QueuedConnection)
2697  && !(types = queuedConnectionTypes(smeta->method(signal_absolute_index).parameterTypes())))
2698  return false;
2699 
2700 #ifndef QT_NO_DEBUG
2701  if (warnCompat) {
2702  QMetaMethod smethod = smeta->method(signal_absolute_index);
2703  QMetaMethod rmethod = rmeta->method(method_index_relative + rmeta->methodOffset());
2704  check_and_warn_compat(smeta, smethod, rmeta, rmethod);
2705  }
2706 #endif
2707  if (!QMetaObjectPrivate::connect(sender, signal_index, receiver, method_index_relative, rmeta ,type, types))
2708  return false;
2709  const_cast<QObject*>(sender)->connectNotify(signal - 1);
2710  return true;
2711 }
2712 
2730 bool QObject::connect(const QObject *sender, const QMetaMethod &signal,
2731  const QObject *receiver, const QMetaMethod &method,
2733 {
2734 #ifndef QT_NO_DEBUG
2735  bool warnCompat = true;
2736 #endif
2737  if (type == Qt::AutoCompatConnection) {
2738  type = Qt::AutoConnection;
2739 #ifndef QT_NO_DEBUG
2740  warnCompat = false;
2741 #endif
2742  }
2743 
2744  if (sender == 0
2745  || receiver == 0
2746  || signal.methodType() != QMetaMethod::Signal
2747  || method.methodType() == QMetaMethod::Constructor) {
2748  qWarning("QObject::connect: Cannot connect %s::%s to %s::%s",
2749  sender ? sender->metaObject()->className() : "(null)",
2750  signal.signature(),
2751  receiver ? receiver->metaObject()->className() : "(null)",
2752  method.signature() );
2753  return false;
2754  }
2755 
2756  QVarLengthArray<char> signalSignature;
2757  QObjectPrivate::signalSignature(signal, &signalSignature);
2758 
2759  {
2760  QByteArray methodSignature;
2761  methodSignature.reserve(qstrlen(method.signature())+1);
2762  methodSignature.append((char)(method.methodType() == QMetaMethod::Slot ? QSLOT_CODE
2763  : method.methodType() == QMetaMethod::Signal ? QSIGNAL_CODE : 0 + '0'));
2764  methodSignature.append(method.signature());
2765  const void *cbdata[] = { sender, signalSignature.constData(), receiver, methodSignature.constData(), &type };
2767  return true;
2768  }
2769 
2770 
2771  int signal_index;
2772  int method_index;
2773  {
2774  int dummy;
2775  QMetaObjectPrivate::memberIndexes(sender, signal, &signal_index, &dummy);
2776  QMetaObjectPrivate::memberIndexes(receiver, method, &dummy, &method_index);
2777  }
2778 
2779  const QMetaObject *smeta = sender->metaObject();
2780  const QMetaObject *rmeta = receiver->metaObject();
2781  if (signal_index == -1) {
2782  qWarning("QObject::connect: Can't find signal %s on instance of class %s",
2783  signal.signature(), smeta->className());
2784  return false;
2785  }
2786  if (method_index == -1) {
2787  qWarning("QObject::connect: Can't find method %s on instance of class %s",
2788  method.signature(), rmeta->className());
2789  return false;
2790  }
2791 
2792  if (!QMetaObject::checkConnectArgs(signal.signature(), method.signature())) {
2793  qWarning("QObject::connect: Incompatible sender/receiver arguments"
2794  "\n %s::%s --> %s::%s",
2795  smeta->className(), signal.signature(),
2796  rmeta->className(), method.signature());
2797  return false;
2798  }
2799 
2800  int *types = 0;
2801  if ((type == Qt::QueuedConnection)
2802  && !(types = queuedConnectionTypes(signal.parameterTypes())))
2803  return false;
2804 
2805 #ifndef QT_NO_DEBUG
2806  if (warnCompat)
2807  check_and_warn_compat(smeta, signal, rmeta, method);
2808 #endif
2809  if (!QMetaObjectPrivate::connect(sender, signal_index, receiver, method_index, 0, type, types))
2810  return false;
2811 
2812  const_cast<QObject*>(sender)->connectNotify(signalSignature.constData());
2813  return true;
2814 }
2815 
2895 bool QObject::disconnect(const QObject *sender, const char *signal,
2896  const QObject *receiver, const char *method)
2897 {
2898  if (sender == 0 || (receiver == 0 && method != 0)) {
2899  qWarning("Object::disconnect: Unexpected null parameter");
2900  return false;
2901  }
2902 
2903  {
2904  const void *cbdata[] = { sender, signal, receiver, method };
2906  return true;
2907  }
2908 
2909  const char *signal_arg = signal;
2910  QByteArray signal_name;
2911  bool signal_found = false;
2912  if (signal) {
2913  QT_TRY {
2914  signal_name = QMetaObject::normalizedSignature(signal);
2915  signal = signal_name.constData();
2916  } QT_CATCH (const std::bad_alloc &) {
2917  // if the signal is already normalized, we can continue.
2918  if (sender->metaObject()->indexOfSignal(signal + 1) == -1)
2919  QT_RETHROW;
2920  }
2921 
2922  if (!check_signal_macro(sender, signal, "disconnect", "unbind"))
2923  return false;
2924  signal++; // skip code
2925  }
2926 
2927  QByteArray method_name;
2928  const char *method_arg = method;
2929  int membcode = -1;
2930  bool method_found = false;
2931  if (method) {
2932  QT_TRY {
2933  method_name = QMetaObject::normalizedSignature(method);
2934  method = method_name.constData();
2935  } QT_CATCH(const std::bad_alloc &) {
2936  // if the method is already normalized, we can continue.
2937  if (receiver->metaObject()->indexOfMethod(method + 1) == -1)
2938  QT_RETHROW;
2939  }
2940 
2941  membcode = extract_code(method);
2942  if (!check_method_code(membcode, receiver, method, "disconnect"))
2943  return false;
2944  method++; // skip code
2945  }
2946 
2947  /* We now iterate through all the sender's and receiver's meta
2948  * objects in order to also disconnect possibly shadowed signals
2949  * and slots with the same signature.
2950  */
2951  bool res = false;
2952  const QMetaObject *smeta = sender->metaObject();
2953  do {
2954  int signal_index = -1;
2955  if (signal) {
2956  signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false);
2957  if (signal_index < 0)
2958  signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true);
2959  if (signal_index < 0)
2960  break;
2961  signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index);
2962  int signalOffset, methodOffset;
2963  computeOffsets(smeta, &signalOffset, &methodOffset);
2964  signal_index += signalOffset;
2965  signal_found = true;
2966  }
2967 
2968  if (!method) {
2969  res |= QMetaObjectPrivate::disconnect(sender, signal_index, receiver, -1);
2970  } else {
2971  const QMetaObject *rmeta = receiver->metaObject();
2972  do {
2973  int method_index = rmeta->indexOfMethod(method);
2974  if (method_index >= 0)
2975  while (method_index < rmeta->methodOffset())
2976  rmeta = rmeta->superClass();
2977  if (method_index < 0)
2978  break;
2979  res |= QMetaObjectPrivate::disconnect(sender, signal_index, receiver, method_index);
2980  method_found = true;
2981  } while ((rmeta = rmeta->superClass()));
2982  }
2983  } while (signal && (smeta = smeta->superClass()));
2984 
2985  if (signal && !signal_found) {
2986  err_method_notfound(sender, signal_arg, "disconnect");
2987  err_info_about_objects("disconnect", sender, receiver);
2988  } else if (method && !method_found) {
2989  err_method_notfound(receiver, method_arg, "disconnect");
2990  err_info_about_objects("disconnect", sender, receiver);
2991  }
2992  if (res)
2993  const_cast<QObject*>(sender)->disconnectNotify(signal ? (signal - 1) : 0);
2994  return res;
2995 }
2996 
3026 bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
3027  const QObject *receiver, const QMetaMethod &method)
3028 {
3029  if (sender == 0 || (receiver == 0 && method.mobj != 0)) {
3030  qWarning("Object::disconnect: Unexpected null parameter");
3031  return false;
3032  }
3033  if (signal.mobj) {
3034  if(signal.methodType() != QMetaMethod::Signal) {
3035  qWarning("Object::%s: Attempt to %s non-signal %s::%s",
3036  "disconnect","unbind",
3037  sender->metaObject()->className(), signal.signature());
3038  return false;
3039  }
3040  }
3041  if (method.mobj) {
3042  if(method.methodType() == QMetaMethod::Constructor) {
3043  qWarning("QObject::disconect: cannot use constructor as argument %s::%s",
3044  receiver->metaObject()->className(), method.signature());
3045  return false;
3046  }
3047  }
3048 
3049  QVarLengthArray<char> signalSignature;
3050  if (signal.mobj)
3051  QObjectPrivate::signalSignature(signal, &signalSignature);
3052 
3053  {
3054  QByteArray methodSignature;
3055  if (method.mobj) {
3056  methodSignature.reserve(qstrlen(method.signature())+1);
3057  methodSignature.append((char)(method.methodType() == QMetaMethod::Slot ? QSLOT_CODE
3058  : method.methodType() == QMetaMethod::Signal ? QSIGNAL_CODE : 0 + '0'));
3059  methodSignature.append(method.signature());
3060  }
3061  const void *cbdata[] = { sender, signal.mobj ? signalSignature.constData() : 0,
3062  receiver, method.mobj ? methodSignature.constData() : 0 };
3064  return true;
3065  }
3066 
3067  int signal_index;
3068  int method_index;
3069  {
3070  int dummy;
3071  QMetaObjectPrivate::memberIndexes(sender, signal, &signal_index, &dummy);
3072  QMetaObjectPrivate::memberIndexes(receiver, method, &dummy, &method_index);
3073  }
3074  // If we are here sender is not null. If signal is not null while signal_index
3075  // is -1 then this signal is not a member of sender.
3076  if (signal.mobj && signal_index == -1) {
3077  qWarning("QObject::disconect: signal %s not found on class %s",
3078  signal.signature(), sender->metaObject()->className());
3079  return false;
3080  }
3081  // If this condition is true then method is not a member of receeiver.
3082  if (receiver && method.mobj && method_index == -1) {
3083  qWarning("QObject::disconect: method %s not found on class %s",
3084  method.signature(), receiver->metaObject()->className());
3085  return false;
3086  }
3087 
3088  if (!QMetaObjectPrivate::disconnect(sender, signal_index, receiver, method_index))
3089  return false;
3090 
3091  const_cast<QObject*>(sender)->disconnectNotify(method.mobj ? signalSignature.constData() : 0);
3092  return true;
3093 }
3094 
3142 void QObject::connectNotify(const char *)
3143 {
3144 }
3145 
3162 void QObject::disconnectNotify(const char *)
3163 {
3164 }
3165 
3166 /* \internal
3167  convert a signal index from the method range to the signal range
3168  */
3169 static int methodIndexToSignalIndex(const QMetaObject *metaObject, int signal_index)
3170 {
3171  if (signal_index < 0)
3172  return signal_index;
3173  while (metaObject && metaObject->methodOffset() > signal_index)
3174  metaObject = metaObject->superClass();
3175 
3176  if (metaObject) {
3177  int signalOffset, methodOffset;
3178  computeOffsets(metaObject, &signalOffset, &methodOffset);
3179  if (signal_index < metaObject->methodCount())
3180  signal_index = QMetaObjectPrivate::originalClone(metaObject, signal_index - methodOffset) + signalOffset;
3181  else
3182  signal_index = signal_index - methodOffset + signalOffset;
3183  }
3184  return signal_index;
3185 }
3186 
3194 bool QMetaObject::connect(const QObject *sender, int signal_index,
3195  const QObject *receiver, int method_index, int type, int *types)
3196 {
3197  signal_index = methodIndexToSignalIndex(sender->metaObject(), signal_index);
3198  return QMetaObjectPrivate::connect(sender, signal_index,
3199  receiver, method_index,
3200  0, //FIXME, we could speed this connection up by computing the relative index
3201  type, types);
3202 }
3203 
3209 bool QMetaObjectPrivate::connect(const QObject *sender, int signal_index,
3210  const QObject *receiver, int method_index,
3211  const QMetaObject *rmeta, int type, int *types)
3212 {
3213  QObject *s = const_cast<QObject *>(sender);
3214  QObject *r = const_cast<QObject *>(receiver);
3215 
3216  int method_offset = rmeta ? rmeta->methodOffset() : 0;
3218  (rmeta && QMetaObjectPrivate::get(rmeta)->revision >= 6 && rmeta->d.extradata)
3219  ? reinterpret_cast<const QMetaObjectExtraData *>(rmeta->d.extradata)->static_metacall : 0;
3220 
3221  QOrderedMutexLocker locker(signalSlotLock(sender),
3222  signalSlotLock(receiver));
3223 
3224  if (type & Qt::UniqueConnection) {
3226  if (connectionLists && connectionLists->count() > signal_index) {
3227  const QObjectPrivate::Connection *c2 =
3228  (*connectionLists)[signal_index].first;
3229 
3230  int method_index_absolute = method_index + method_offset;
3231 
3232  while (c2) {
3233  if (c2->receiver == receiver && c2->method() == method_index_absolute)
3234  return false;
3235  c2 = c2->nextConnectionList;
3236  }
3237  }
3238  type &= Qt::UniqueConnection - 1;
3239  }
3240 
3242  c->sender = s;
3243  c->receiver = r;
3244  c->method_relative = method_index;
3245  c->method_offset = method_offset;
3246  c->connectionType = type;
3247  c->argumentTypes = types;
3248  c->nextConnectionList = 0;
3249  c->callFunction = callFunction;
3250 
3251  QT_TRY {
3252  QObjectPrivate::get(s)->addConnection(signal_index, c);
3253  } QT_CATCH(...) {
3254  delete c;
3255  QT_RETHROW;
3256  }
3257 
3258  c->prev = &(QObjectPrivate::get(r)->senders);
3259  c->next = *c->prev;
3260  *c->prev = c;
3261  if (c->next)
3262  c->next->prev = &c->next;
3263 
3264  QObjectPrivate *const sender_d = QObjectPrivate::get(s);
3265  if (signal_index < 0) {
3266  sender_d->connectedSignals[0] = sender_d->connectedSignals[1] = ~0;
3267  } else if (signal_index < (int)sizeof(sender_d->connectedSignals) * 8) {
3268  sender_d->connectedSignals[signal_index >> 5] |= (1 << (signal_index & 0x1f));
3269  }
3270 
3271  return true;
3272 }
3273 
3276 bool QMetaObject::disconnect(const QObject *sender, int signal_index,
3277  const QObject *receiver, int method_index)
3278 {
3279  signal_index = methodIndexToSignalIndex(sender->metaObject(), signal_index);
3280  return QMetaObjectPrivate::disconnect(sender, signal_index,
3281  receiver, method_index);
3282 }
3283 
3290 bool QMetaObject::disconnectOne(const QObject *sender, int signal_index,
3291  const QObject *receiver, int method_index)
3292 {
3293  signal_index = methodIndexToSignalIndex(sender->metaObject(), signal_index);
3294  return QMetaObjectPrivate::disconnect(sender, signal_index,
3295  receiver, method_index,
3297 }
3298 
3303  const QObject *receiver, int method_index,
3304  QMutex *senderMutex, DisconnectType disconnectType)
3305 {
3306  bool success = false;
3307  while (c) {
3308  if (c->receiver
3309  && (receiver == 0 || (c->receiver == receiver
3310  && (method_index < 0 || c->method() == method_index)))) {
3311  bool needToUnlock = false;
3312  QMutex *receiverMutex = 0;
3313  if (!receiver) {
3314  receiverMutex = signalSlotLock(c->receiver);
3315  // need to relock this receiver and sender in the correct order
3316  needToUnlock = QOrderedMutexLocker::relock(senderMutex, receiverMutex);
3317  }
3318  if (c->receiver) {
3319  *c->prev = c->next;
3320  if (c->next)
3321  c->next->prev = c->prev;
3322  }
3323 
3324  if (needToUnlock)
3325  receiverMutex->unlockInline();
3326 
3327  c->receiver = 0;
3328 
3329  success = true;
3330 
3331  if (disconnectType == DisconnectOne)
3332  return success;
3333  }
3334  c = c->nextConnectionList;
3335  }
3336  return success;
3337 }
3338 
3342 bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index,
3343  const QObject *receiver, int method_index,
3344  DisconnectType disconnectType)
3345 {
3346  if (!sender)
3347  return false;
3348 
3349  QObject *s = const_cast<QObject *>(sender);
3350 
3351  QMutex *senderMutex = signalSlotLock(sender);
3352  QMutex *receiverMutex = receiver ? signalSlotLock(receiver) : 0;
3353  QOrderedMutexLocker locker(senderMutex, receiverMutex);
3354 
3356  if (!connectionLists)
3357  return false;
3358 
3359  // prevent incoming connections changing the connectionLists while unlocked
3360  ++connectionLists->inUse;
3361 
3362  bool success = false;
3363  if (signal_index < 0) {
3364  // remove from all connection lists
3365  for (signal_index = -1; signal_index < connectionLists->count(); ++signal_index) {
3367  (*connectionLists)[signal_index].first;
3368  if (disconnectHelper(c, receiver, method_index, senderMutex, disconnectType)) {
3369  success = true;
3370  connectionLists->dirty = true;
3371  }
3372  }
3373  } else if (signal_index < connectionLists->count()) {
3375  (*connectionLists)[signal_index].first;
3376  if (disconnectHelper(c, receiver, method_index, senderMutex, disconnectType)) {
3377  success = true;
3378  connectionLists->dirty = true;
3379  }
3380  }
3381 
3382  --connectionLists->inUse;
3383  Q_ASSERT(connectionLists->inUse >= 0);
3384  if (connectionLists->orphaned && !connectionLists->inUse)
3385  delete connectionLists;
3386 
3387  return success;
3388 }
3389 
3407 {
3408  if (!o)
3409  return;
3410  const QMetaObject *mo = o->metaObject();
3411  Q_ASSERT(mo);
3412  const QObjectList list = o->findChildren<QObject *>(QString());
3413  for (int i = 0; i < mo->methodCount(); ++i) {
3414  const char *slot = mo->method(i).signature();
3415  Q_ASSERT(slot);
3416  if (slot[0] != 'o' || slot[1] != 'n' || slot[2] != '_')
3417  continue;
3418  bool foundIt = false;
3419  for(int j = 0; j < list.count(); ++j) {
3420  const QObject *co = list.at(j);
3421  QByteArray objName = co->objectName().toAscii();
3422  int len = objName.length();
3423  if (!len || qstrncmp(slot + 3, objName.data(), len) || slot[len+3] != '_')
3424  continue;
3425  int sigIndex = co->d_func()->signalIndex(slot + len + 4);
3426  if (sigIndex < 0) { // search for compatible signals
3427  const QMetaObject *smo = co->metaObject();
3428  int slotlen = qstrlen(slot + len + 4) - 1;
3429  for (int k = 0; k < co->metaObject()->methodCount(); ++k) {
3430  QMetaMethod method = smo->method(k);
3431  if (method.methodType() != QMetaMethod::Signal)
3432  continue;
3433 
3434  if (!qstrncmp(method.signature(), slot + len + 4, slotlen)) {
3435  int signalOffset, methodOffset;
3436  computeOffsets(method.enclosingMetaObject(), &signalOffset, &methodOffset);
3437  sigIndex = k + - methodOffset + signalOffset;
3438  break;
3439  }
3440  }
3441  }
3442  if (sigIndex < 0)
3443  continue;
3444  if (QMetaObjectPrivate::connect(co, sigIndex, o, i)) {
3445  foundIt = true;
3446  break;
3447  }
3448  }
3449  if (foundIt) {
3450  // we found our slot, now skip all overloads
3451  while (mo->method(i + 1).attributes() & QMetaMethod::Cloned)
3452  ++i;
3453  } else if (!(mo->method(i).attributes() & QMetaMethod::Cloned)) {
3454  qWarning("QMetaObject::connectSlotsByName: No matching signal for %s", slot);
3455  }
3456  }
3457 }
3458 
3459 static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv)
3460 {
3462  QMetaMethod m = sender->metaObject()->method(signal);
3463  int *tmp = queuedConnectionTypes(m.parameterTypes());
3464  if (!tmp) // cannot queue arguments
3465  tmp = &DIRECT_CONNECTION_ONLY;
3466  if (!c->argumentTypes.testAndSetOrdered(0, tmp)) {
3467  if (tmp != &DIRECT_CONNECTION_ONLY)
3468  delete [] tmp;
3469  }
3470  }
3471  if (c->argumentTypes == &DIRECT_CONNECTION_ONLY) // cannot activate
3472  return;
3473  int nargs = 1; // include return type
3474  while (c->argumentTypes[nargs-1])
3475  ++nargs;
3476  int *types = (int *) qMalloc(nargs*sizeof(int));
3477  Q_CHECK_PTR(types);
3478  void **args = (void **) qMalloc(nargs*sizeof(void *));
3479  Q_CHECK_PTR(args);
3480  types[0] = 0; // return type
3481  args[0] = 0; // return value
3482  for (int n = 1; n < nargs; ++n)
3483  args[n] = QMetaType::construct((types[n] = c->argumentTypes[n-1]), argv[n]);
3485  c->method_relative,
3486  c->callFunction,
3487  sender, signal, nargs,
3488  types, args));
3489 }
3490 
3491 
3496 void QMetaObject::activate(QObject *sender, int from_signal_index, int to_signal_index, void **argv)
3497 {
3498  Q_UNUSED(to_signal_index);
3499  activate(sender, from_signal_index, argv);
3500 }
3501 
3504 void QMetaObject::activate(QObject *sender, const QMetaObject *m, int local_signal_index,
3505  void **argv)
3506 {
3507  int signalOffset;
3508  int methodOffset;
3509  computeOffsets(m, &signalOffset, &methodOffset);
3510 
3511  int signal_index = signalOffset + local_signal_index;
3512 
3513  if (!sender->d_func()->isSignalConnected(signal_index))
3514  return; // nothing connected to these signals, and no spy
3515 
3516  if (sender->d_func()->blockSig)
3517  return;
3518 
3519  int signal_absolute_index = methodOffset + local_signal_index;
3520 
3521  void *empty_argv[] = { 0 };
3523  qt_signal_spy_callback_set.signal_begin_callback(sender, signal_absolute_index,
3524  argv ? argv : empty_argv);
3525  }
3526 
3527  Qt::HANDLE currentThreadId = QThread::currentThreadId();
3528 
3529  QMutexLocker locker(signalSlotLock(sender));
3530  QObjectConnectionListVector *connectionLists = sender->d_func()->connectionLists;
3531  if (!connectionLists) {
3532  locker.unlock();
3534  qt_signal_spy_callback_set.signal_end_callback(sender, signal_absolute_index);
3535  return;
3536  }
3537  ++connectionLists->inUse;
3538 
3539 
3540  const QObjectPrivate::ConnectionList *list;
3541  if (signal_index < connectionLists->count())
3542  list = &connectionLists->at(signal_index);
3543  else
3544  list = &connectionLists->allsignals;
3545 
3546  do {
3548  if (!c) continue;
3549  // We need to check against last here to ensure that signals added
3550  // during the signal emission are not emitted in this emission.
3551  QObjectPrivate::Connection *last = list->last;
3552 
3553  do {
3554  if (!c->receiver)
3555  continue;
3556 
3557  QObject * const receiver = c->receiver;
3558  const bool receiverInSameThread = currentThreadId == receiver->d_func()->threadData->threadId;
3559 
3560  // determine if this connection should be sent immediately or
3561  // put into the event queue
3562  if ((c->connectionType == Qt::AutoConnection && !receiverInSameThread)
3563  || (c->connectionType == Qt::QueuedConnection)) {
3564  queued_activate(sender, signal_absolute_index, c, argv ? argv : empty_argv);
3565  continue;
3566 #ifndef QT_NO_THREAD
3567  } else if (c->connectionType == Qt::BlockingQueuedConnection) {
3568  locker.unlock();
3569  if (receiverInSameThread) {
3570  qWarning("Qt: Dead lock detected while activating a BlockingQueuedConnection: "
3571  "Sender is %s(%p), receiver is %s(%p)",
3572  sender->metaObject()->className(), sender,
3573  receiver->metaObject()->className(), receiver);
3574  }
3575  QSemaphore semaphore;
3577  c->callFunction,
3578  sender, signal_absolute_index,
3579  0, 0,
3580  argv ? argv : empty_argv,
3581  &semaphore));
3582  semaphore.acquire();
3583  locker.relock();
3584  continue;
3585 #endif
3586  }
3587 
3588  QObjectPrivate::Sender currentSender;
3589  QObjectPrivate::Sender *previousSender = 0;
3590  if (receiverInSameThread) {
3591  currentSender.sender = sender;
3592  currentSender.signal = signal_absolute_index;
3593  currentSender.ref = 1;
3594  previousSender = QObjectPrivate::setCurrentSender(receiver, &currentSender);
3595  }
3596  const QObjectPrivate::StaticMetaCallFunction callFunction = c->callFunction;
3597  const int method_relative = c->method_relative;
3598  if (callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) {
3599  //we compare the vtable to make sure we are not in the destructor of the object.
3600  locker.unlock();
3602  qt_signal_spy_callback_set.slot_begin_callback(receiver, c->method(), argv ? argv : empty_argv);
3603 
3604 #if defined(QT_NO_EXCEPTIONS)
3605  callFunction(receiver, QMetaObject::InvokeMetaMethod, method_relative, argv ? argv : empty_argv);
3606 #else
3607  QT_TRY {
3608  callFunction(receiver, QMetaObject::InvokeMetaMethod, method_relative, argv ? argv : empty_argv);
3609  } QT_CATCH(...) {
3610  locker.relock();
3611  if (receiverInSameThread)
3612  QObjectPrivate::resetCurrentSender(receiver, &currentSender, previousSender);
3613 
3614  --connectionLists->inUse;
3615  Q_ASSERT(connectionLists->inUse >= 0);
3616  if (connectionLists->orphaned && !connectionLists->inUse)
3617  delete connectionLists;
3618  QT_RETHROW;
3619  }
3620 #endif
3623  locker.relock();
3624  } else {
3625  const int method = method_relative + c->method_offset;
3626  locker.unlock();
3627 
3630  method,
3631  argv ? argv : empty_argv);
3632  }
3633 
3634 #if defined(QT_NO_EXCEPTIONS)
3635  metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
3636 #else
3637  QT_TRY {
3638  metacall(receiver, QMetaObject::InvokeMetaMethod, method, argv ? argv : empty_argv);
3639  } QT_CATCH(...) {
3640  locker.relock();
3641  if (receiverInSameThread)
3642  QObjectPrivate::resetCurrentSender(receiver, &currentSender, previousSender);
3643 
3644  --connectionLists->inUse;
3645  Q_ASSERT(connectionLists->inUse >= 0);
3646  if (connectionLists->orphaned && !connectionLists->inUse)
3647  delete connectionLists;
3648  QT_RETHROW;
3649  }
3650 #endif
3651 
3654 
3655  locker.relock();
3656  }
3657 
3658  if (receiverInSameThread)
3659  QObjectPrivate::resetCurrentSender(receiver, &currentSender, previousSender);
3660 
3661  if (connectionLists->orphaned)
3662  break;
3663  } while (c != last && (c = c->nextConnectionList) != 0);
3664 
3665  if (connectionLists->orphaned)
3666  break;
3667  } while (list != &connectionLists->allsignals &&
3668  //start over for all signals;
3669  ((list = &connectionLists->allsignals), true));
3670 
3671  --connectionLists->inUse;
3672  Q_ASSERT(connectionLists->inUse >= 0);
3673  if (connectionLists->orphaned) {
3674  if (!connectionLists->inUse)
3675  delete connectionLists;
3676  } else if (connectionLists->dirty) {
3677  sender->d_func()->cleanConnectionLists();
3678  }
3679 
3680  locker.unlock();
3681 
3683  qt_signal_spy_callback_set.signal_end_callback(sender, signal_absolute_index);
3684 
3685 }
3686 
3690 void QMetaObject::activate(QObject *sender, int signal_index, void **argv)
3691 {
3692  const QMetaObject *mo = sender->metaObject();
3693  while (mo->methodOffset() > signal_index)
3694  mo = mo->superClass();
3695  activate(sender, mo, signal_index - mo->methodOffset(), argv);
3696 }
3697 
3702 void QMetaObject::activate(QObject *sender, const QMetaObject *m,
3703  int from_local_signal_index, int to_local_signal_index, void **argv)
3704 {
3705  Q_UNUSED(to_local_signal_index);
3706  Q_ASSERT(from_local_signal_index == QMetaObjectPrivate::originalClone(m, to_local_signal_index));
3707  activate(sender, m, from_local_signal_index, argv);
3708 }
3709 
3720 {
3721  Q_Q(const QObject);
3722  const QMetaObject *base = q->metaObject();
3723  int relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, false);
3724  if (relative_index < 0)
3725  relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, true);
3726  if (relative_index < 0)
3727  return relative_index;
3728  relative_index = QMetaObjectPrivate::originalClone(base, relative_index);
3729  int signalOffset, methodOffset;
3730  computeOffsets(base, &signalOffset, &methodOffset);
3731  return relative_index + signalOffset;
3732 }
3733 
3734 /*****************************************************************************
3735  Properties
3736  *****************************************************************************/
3737 
3738 #ifndef QT_NO_PROPERTIES
3739 
3755 bool QObject::setProperty(const char *name, const QVariant &value)
3756 {
3757  Q_D(QObject);
3758  const QMetaObject* meta = metaObject();
3759  if (!name || !meta)
3760  return false;
3761 
3762  int id = meta->indexOfProperty(name);
3763  if (id < 0) {
3764  if (!d->extraData)
3766 
3767  const int idx = d->extraData->propertyNames.indexOf(name);
3768 
3769  if (!value.isValid()) {
3770  if (idx == -1)
3771  return false;
3772  d->extraData->propertyNames.removeAt(idx);
3774  } else {
3775  if (idx == -1) {
3776  d->extraData->propertyNames.append(name);
3777  d->extraData->propertyValues.append(value);
3778  } else {
3779  d->extraData->propertyValues[idx] = value;
3780  }
3781  }
3782 
3783  QDynamicPropertyChangeEvent ev(name);
3784  QCoreApplication::sendEvent(this, &ev);
3785 
3786  return false;
3787  }
3788  QMetaProperty p = meta->property(id);
3789 #ifndef QT_NO_DEBUG
3790  if (!p.isWritable())
3791  qWarning("%s::setProperty: Property \"%s\" invalid,"
3792  " read-only or does not exist", metaObject()->className(), name);
3793 #endif
3794  return p.write(this, value);
3795 }
3796 
3807 QVariant QObject::property(const char *name) const
3808 {
3809  Q_D(const QObject);
3810  const QMetaObject* meta = metaObject();
3811  if (!name || !meta)
3812  return QVariant();
3813 
3814  int id = meta->indexOfProperty(name);
3815  if (id < 0) {
3816  if (!d->extraData)
3817  return QVariant();
3818  const int i = d->extraData->propertyNames.indexOf(name);
3819  return d->extraData->propertyValues.value(i);
3820  }
3821  QMetaProperty p = meta->property(id);
3822 #ifndef QT_NO_DEBUG
3823  if (!p.isReadable())
3824  qWarning("%s::property: Property \"%s\" invalid or does not exist",
3825  metaObject()->className(), name);
3826 #endif
3827  return p.read(this);
3828 }
3829 
3840 {
3841  Q_D(const QObject);
3842  if (d->extraData)
3843  return d->extraData->propertyNames;
3844  return QList<QByteArray>();
3845 }
3846 
3847 #endif // QT_NO_PROPERTIES
3848 
3849 
3850 /*****************************************************************************
3851  QObject debugging output routines.
3852  *****************************************************************************/
3853 
3854 static void dumpRecursive(int level, QObject *object)
3855 {
3856 #if defined(QT_DEBUG)
3857  if (object) {
3858  QByteArray buf;
3859  buf.fill(' ', level / 2 * 8);
3860  if (level % 2)
3861  buf += " ";
3862  QString name = object->objectName();
3863  QString flags = QLatin1String("");
3864 #if 0
3865  if (qApp->focusWidget() == object)
3866  flags += 'F';
3867  if (object->isWidgetType()) {
3868  QWidget * w = (QWidget *)object;
3869  if (w->isVisible()) {
3870  QString t("<%1,%2,%3,%4>");
3871  flags += t.arg(w->x()).arg(w->y()).arg(w->width()).arg(w->height());
3872  } else {
3873  flags += 'I';
3874  }
3875  }
3876 #endif
3877  qDebug("%s%s::%s %s", (const char*)buf, object->metaObject()->className(), name.toLocal8Bit().data(),
3878  flags.toLatin1().data());
3879  QObjectList children = object->children();
3880  if (!children.isEmpty()) {
3881  for (int i = 0; i < children.size(); ++i)
3882  dumpRecursive(level+1, children.at(i));
3883  }
3884  }
3885 #else
3886  Q_UNUSED(level)
3887  Q_UNUSED(object)
3888 #endif
3889 }
3890 
3902 {
3903  dumpRecursive(0, this);
3904 }
3905 
3918 {
3919 #if defined(QT_DEBUG)
3920  qDebug("OBJECT %s::%s", metaObject()->className(),
3921  objectName().isEmpty() ? "unnamed" : objectName().toLocal8Bit().data());
3922 
3923  Q_D(QObject);
3924  QMutexLocker locker(signalSlotLock(this));
3925 
3926  // first, look for connections where this object is the sender
3927  qDebug(" SIGNALS OUT");
3928 
3929  if (d->connectionLists) {
3930  int offset = 0;
3931  int offsetToNextMetaObject = 0;
3932  for (int signal_index = 0; signal_index < d->connectionLists->count(); ++signal_index) {
3933  if (signal_index >= offsetToNextMetaObject) {
3934  const QMetaObject *mo = metaObject();
3935  int signalOffset, methodOffset;
3936  computeOffsets(mo, &signalOffset, &methodOffset);
3937  while (signalOffset > signal_index) {
3938  mo = mo->superClass();
3939  offsetToNextMetaObject = signalOffset;
3940  computeOffsets(mo, &signalOffset, &methodOffset);
3941  }
3942  offset = methodOffset - signalOffset;
3943  }
3944  const QMetaMethod signal = metaObject()->method(signal_index + offset);
3945  qDebug(" signal: %s", signal.signature());
3946 
3947  // receivers
3948  const QObjectPrivate::Connection *c =
3949  d->connectionLists->at(signal_index).first;
3950  while (c) {
3951  if (!c->receiver) {
3952  qDebug(" <Disconnected receiver>");
3953  c = c->nextConnectionList;
3954  continue;
3955  }
3956  const QMetaObject *receiverMetaObject = c->receiver->metaObject();
3957  const QMetaMethod method = receiverMetaObject->method(c->method());
3958  qDebug(" --> %s::%s %s",
3959  receiverMetaObject->className(),
3960  c->receiver->objectName().isEmpty() ? "unnamed" : qPrintable(c->receiver->objectName()),
3961  method.signature());
3962  c = c->nextConnectionList;
3963  }
3964  }
3965  } else {
3966  qDebug( " <None>" );
3967  }
3968 
3969  // now look for connections where this object is the receiver
3970  qDebug(" SIGNALS IN");
3971 
3972  if (d->senders) {
3973  for (QObjectPrivate::Connection *s = d->senders; s; s = s->next) {
3974  const QMetaMethod slot = metaObject()->method(s->method());
3975  qDebug(" <-- %s::%s %s",
3976  s->sender->metaObject()->className(),
3977  s->sender->objectName().isEmpty() ? "unnamed" : qPrintable(s->sender->objectName()),
3978  slot.signature());
3979  }
3980  } else {
3981  qDebug(" <None>");
3982  }
3983 #endif
3984 }
3985 
3986 #ifndef QT_NO_USERDATA
3987 
3990 {
3991  static int user_data_registration = 0;
3992  return user_data_registration++;
3993 }
3994 
3998 {
3999 }
4000 
4004 {
4005  Q_D(QObject);
4006  if (!d->extraData)
4008 
4009  if (d->extraData->userData.size() <= (int) id)
4010  d->extraData->userData.resize((int) id + 1);
4011  d->extraData->userData[id] = data;
4012 }
4013 
4017 {
4018  Q_D(const QObject);
4019  if (!d->extraData)
4020  return 0;
4021  if ((int)id < d->extraData->userData.size())
4022  return d->extraData->userData.at(id);
4023  return 0;
4024 }
4025 
4026 #endif // QT_NO_USERDATA
4027 
4028 
4029 #ifndef QT_NO_DEBUG_STREAM
4030 QDebug operator<<(QDebug dbg, const QObject *o) {
4031 #ifndef Q_BROKEN_DEBUG_STREAM
4032  if (!o)
4033  return dbg << "QObject(0x0) ";
4034  dbg.nospace() << o->metaObject()->className() << '(' << (void *)o;
4035  if (!o->objectName().isEmpty())
4036  dbg << ", name = " << o->objectName();
4037  dbg << ')';
4038  return dbg.space();
4039 #else
4040  qWarning("This compiler doesn't support streaming QObject to QDebug");
4041  return dbg;
4042  Q_UNUSED(o);
4043 #endif
4044 }
4045 #endif
4046 
4348 void qDeleteInEventHandler(QObject *o)
4349 {
4350 #ifdef QT_JAMBI_BUILD
4351  if (!o)
4352  return;
4353  QObjectPrivate::get(o)->inEventHandler = false;
4354 #endif
4355  delete o;
4356 }
4357 
4358 
4360 
4361 #include "moc_qobject.cpp"
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static void clearGuards(QObject *)
Definition: qobject.cpp:467
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
The QMultiHash class is a convenience QHash subclass that provides multi-valued hashes.
Definition: qcontainerfwd.h:58
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
virtual ~QObject()
Destroys the object, deleting all its child objects.
Definition: qobject.cpp:853
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
const T * constData() const
static Sender * setCurrentSender(QObject *receiver, Sender *sender)
Definition: qobject_p.h:269
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
BeginCallback slot_begin_callback
Definition: qobject_p.h:79
int type
Definition: qmetatype.cpp:239
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
QByteArray & fill(char c, int size=-1)
Sets every byte in the byte array to character ch.
unsigned char c[8]
Definition: qnumeric_p.h:62
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
const void * extradata
Definition: qobjectdefs.h:472
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QSemaphore class provides a general counting semaphore.
Definition: qsemaphore.h:57
QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction, const QObject *sender, int signalId, int nargs=0, int *types=0, void **args=0, QSemaphore *semaphore=0)
Definition: qobject.cpp:493
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
static QByteArray normalizedSignature(const char *method)
Normalizes the signature of the given method.
EndCallback slot_end_callback
Definition: qobject_p.h:81
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static void signalSignature(const QMetaMethod &signal, QVarLengthArray< char > *result)
Definition: qobject_p.h:255
void qt_qFindChildren_helper(const QObject *parent, const QString &name, const QRegExp *re, const QMetaObject &mo, QList< void *> *list)
Definition: qobject.cpp:1900
Q_CORE_EXPORT void qt_addObject(QObject *)
Definition: qobject.cpp:114
QObjectPrivate::StaticMetaCallFunction callFunction_
Definition: qobject_p.h:315
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
static QBasicAtomicInt objectCount
Definition: qobject.cpp:98
QSemaphore * semaphore_
Definition: qobject_p.h:314
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index_relative, const QMetaObject *rmeta=0, int type=0, int *types=0)
Definition: qobject.cpp:3209
QObjectPrivate::ConnectionList allsignals
Definition: qobject.cpp:260
#define it(className, varName)
QObject * q_ptr
Definition: qobject.h:91
static const char * extract_location(const char *member)
Definition: qobject.cpp:2234
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QByteArray & append(char c)
Appends the character ch to this byte array.
void moveToThread_helper()
Definition: qobject.cpp:1513
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...
const QObject * sender() const
Definition: qobject_p.h:302
bool isVisible() const
Definition: qwidget.h:1005
Connection * senders
Definition: qobject_p.h:199
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
static int metacall(QObject *, Call, int, void **)
void addConnection(int signal, Connection *c)
Definition: qobject.cpp:330
Q_CORE_EXPORT void qFree(void *ptr)
Definition: qmalloc.cpp:58
QString objectName
the name of this object
Definition: qobject.h:114
QMultiHash< QObject *, QObject ** > GuardHash
Definition: qobject.cpp:384
#define at(className, varName)
static void memberIndexes(const QObject *obj, const QMetaMethod &member, int *signalIndex, int *methodIndex)
This helper function calculates signal and method index for the given member in the specified class...
Definition: qobject.cpp:2468
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setUserData(uint id, QObjectUserData *data)
Definition: qobject.cpp:4003
int senderSignalIndex() const
Definition: qobject.cpp:2368
QObjectUserData * userData(uint id) const
Definition: qobject.cpp:4016
static void computeOffsets(const QMetaObject *metaobject, int *signalOffset, int *methodOffset)
Definition: qobject.cpp:225
QObjectList senderList() const
Definition: qobject.cpp:321
T1 first
Definition: qpair.h:65
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void cleanConnectionLists()
Definition: qobject.cpp:348
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
void unlock()
Unlocks this mutex locker.
Definition: qmutex.h:117
T2 second
Definition: qpair.h:66
void * qt_find_obj_child(QObject *parent, const char *type, const QString &name)
Returns a pointer to the object named name that inherits type and with a given parent.
Definition: qobject.cpp:700
T & operator[](int i)
Returns the item at index position i as a modifiable reference.
Definition: qvector.h:358
static void connectSlotsByName(QObject *o)
Searches recursively for all child objects of the given object, and connects matching signals from th...
Definition: qobject.cpp:3406
uint hasGuards
Definition: qobject.h:104
uint wasDeleted
Definition: qobject.h:98
The QDynamicPropertyChangeEvent class contains event parameters for dynamic property change events...
Definition: qcoreevent.h:380
void addEvent(const QPostEvent &ev)
Definition: qthread_p.h:115
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
bool testAndSetOrdered(T *expectedValue, T *newValue)
uint isWidget
Definition: qobject.h:95
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
FlaggedDebugSignatures flaggedSignatures
Definition: qthread_p.h:275
bool canWait
Definition: qthread_p.h:267
void release(int n=1)
Releases n resources guarded by the semaphore.
Definition: qsemaphore.cpp:161
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static void dumpRecursive(int level, QObject *object)
Definition: qobject.cpp:3854
virtual bool unregisterTimer(int timerId)=0
Unregisters the timer with the given timerId.
Q_CORE_EXPORT void * qMalloc(size_t size)
Definition: qmalloc.cpp:53
T & value() const
Returns a modifiable reference to the current item&#39;s value.
Definition: qhash.h:348
QDebug operator<<(QDebug dbg, const QObject *o)
Definition: qobject.cpp:4030
The QString class provides a Unicode character string.
Definition: qstring.h:83
static int indexOfSignalRelative(const QMetaObject **baseObject, const char *name, bool normalizeStringData)
Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static int DIRECT_CONNECTION_ONLY
Definition: qobject.cpp:71
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
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
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
Sender * currentSender
Definition: qobject_p.h:200
void ** args_
Definition: qobject_p.h:313
static bool check_signal_macro(const QObject *sender, const char *signal, const char *func, const char *op)
Definition: qobject.cpp:2245
#define Q_D(Class)
Definition: qglobal.h:2482
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
virtual void connectNotify(const char *signal)
This virtual function is called when something has been connected to signal in this object...
Definition: qobject.cpp:3142
static const uint base
Definition: qurl.cpp:268
int indexOfProperty(const char *name) const
Finds property name and returns its index; otherwise returns -1.
static void(* objectNameChanged)(QAbstractDeclarativeData *, QObject *)
Definition: qobject_p.h:95
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
ushort method_relative_
Definition: qobject_p.h:317
QObjectList children
Definition: qobject.h:93
QThreadData * threadData
Definition: qobject_p.h:195
QHash< Key, T >::iterator find(const Key &key, const T &value)
Returns an iterator pointing to the item with the key and value.
Definition: qhash.h:972
static void * construct(int type, const void *copy=0)
Returns a copy of copy, assuming it is of type type.
Definition: qmetatype.cpp:1042
const char * className
Definition: qwizard.cpp:137
BeginCallback signal_begin_callback
Definition: qobject_p.h:79
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void deref()
Definition: qthread.cpp:125
static bool disconnectHelper(QObjectPrivate::Connection *c, const QObject *receiver, int method_index, QMutex *senderMutex, DisconnectType)
Definition: qobject.cpp:3302
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition: qobject.cpp:2327
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
static int methodIndexToSignalIndex(const QMetaObject *metaObject, int signal_index)
Definition: qobject.cpp:3169
void relock()
Relocks an unlocked mutex locker.
Definition: qmutex.h:125
QObject * cast(QObject *obj) const
Returns obj if object obj inherits from this meta-object; otherwise returns 0.
static void err_info_about_objects(const char *func, const QObject *sender, const QObject *receiver)
Definition: qobject.cpp:2293
ConnectionType
Definition: qnamespace.h:1469
QList< QPointer< QObject > > eventFilters
Definition: qobject_p.h:211
Q_CORE_EXPORT void qDebug(const char *,...)
static void err_method_notfound(const QObject *object, const char *method, const char *func)
Definition: qobject.cpp:2272
virtual QList< TimerInfo > registeredTimers(QObject *object) const =0
Returns a list of registered timers for object.
#define QT_RETHROW
Definition: qglobal.h:1539
void setParent_helper(QObject *)
Definition: qobject.cpp:1974
static QThreadData * get2(QThread *thread)
Definition: qthread_p.h:219
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
ushort method_offset_
Definition: qobject_p.h:316
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
uint blockSig
Definition: qobject.h:97
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
static bool isEmpty(const char *str)
int methodOffset() const
Returns the method offset for this class; i.e.
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
Definition: qregexp.cpp:4136
QObjectPrivate(int version=QObjectPrivateVersion)
Definition: qobject.cpp:133
static bool activateCallbacks(Callback, void **)
Definition: qglobal.cpp:3653
const char * typeName
Definition: qmetatype.cpp:239
void(* StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **)
Definition: qobject_p.h:113
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
virtual void childEvent(QChildEvent *)
This event handler can be reimplemented in a subclass to receive child events.
Definition: qobject.cpp:1332
static void changeGuard(QObject **ptr, QObject *o)
Definition: qobject.cpp:435
static QBasicAtomicPointer< QMutexPool > signalSlotMutexes
Definition: qobject.cpp:97
static bool check_method_code(int code, const QObject *object, const char *method, const char *func)
Definition: qobject.cpp:2261
QMutex mutex
Definition: qthread_p.h:109
const char * name
void unlockInline()
Definition: qmutex.h:196
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
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
QList< QVariant > propertyValues
Definition: qobject_p.h:110
bool isEmpty() const
Returns true if the hash contains no items; otherwise returns false.
Definition: qhash.h:297
Q_CORE_EXPORT void qWarning(const char *,...)
uint inThreadChangeEvent
Definition: qobject.h:103
int receivers(const char *signal) const
Returns the number of receivers connected to the signal.
Definition: qobject.cpp:2406
QBasicAtomicPointer< int > argumentTypes
Definition: qobject_p.h:124
const QMetaObject * enclosingMetaObject() const
Definition: qmetaobject.h:75
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QList< QByteArray > propertyNames
Definition: qobject_p.h:109
QPostEventList postEventList
Definition: qthread_p.h:266
quint32 connectedSignals[2]
Definition: qobject_p.h:201
int registerTimer(int interval, QObject *object)
Registers a timer with the specified interval for the given object.
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3276
static void destroy(int type, void *data)
Destroys the data, assuming it is of the type given.
Definition: qmetatype.cpp:1263
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
static bool checkConnectArgs(const char *signal, const char *method)
Returns true if the signal and method arguments are compatible; otherwise returns false...
QMutex * get(const void *address)
Returns a QMutex from the pool.
Definition: qmutexpool_p.h:70
static void resetCurrentSender(QObject *receiver, Sender *currentSender, Sender *previousSender)
Definition: qobject_p.h:277
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
const T * ptr(const T &t)
virtual ~QObjectPrivate()
Definition: qobject.cpp:161
virtual void wakeUp()=0
Wakes up the event loop.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
void clear()
Removes all items from the list.
Definition: qlist.h:764
void deleteChildren()
Definition: qobject.cpp:1957
T * fetchAndStoreAcquire(T *newValue)
const Key & key() const
Returns the current item&#39;s key as a const reference.
Definition: qhash.h:347
void * HANDLE
Definition: qnamespace.h:1671
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
virtual ~QObjectUserData()
Definition: qobject.cpp:3997
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
QVector< QObjectUserData * > userData
Definition: qobject_p.h:107
static uint registerUserData()
Definition: qobject.cpp:3989
#define QT_CATCH(A)
Definition: qglobal.h:1537
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
QString objectName
Definition: qobject_p.h:193
void _q_reregisterTimers(void *pointer)
Definition: qobject.cpp:1571
EndCallback signal_end_callback
Definition: qobject_p.h:81
virtual void customEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive custom events.
Definition: qobject.cpp:1346
Q_CORE_EXPORT void qt_removeObject(QObject *)
Definition: qobject.cpp:119
uint inEventHandler
Definition: qobject.h:102
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static QMutex * signalSlotLock(const QObject *o)
Definition: qobject.cpp:103
virtual bool eventFilter(QObject *, QEvent *)
Filters events if this object has been installed as an event filter for the watched object...
Definition: qobject.cpp:1375
static int originalClone(const QMetaObject *obj, int local_method_index)
int length() const
Same as size().
Definition: qbytearray.h:356
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
bool isSender(const QObject *receiver, const char *signal) const
Definition: qobject.cpp:275
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
QHash< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:934
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
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
Connection * nextConnectionList
Definition: qobject_p.h:120
#define QSIGNAL_CODE
Definition: qobjectdefs.h:244
QEvent * event
Definition: qthread_p.h:78
uint qstrlen(const char *str)
Definition: qbytearray.h:79
Q_CORE_EXPORT void qFatal(const char *,...)
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void store(const char *method)
Definition: qthread_p.h:248
void qDeleteInEventHandler(QObject *o)
Definition: qobject.cpp:4348
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
void ref()
Definition: qthread.cpp:117
QObject * receiver
Definition: qthread_p.h:77
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
static const struct @32 types[]
virtual void disconnectNotify(const char *signal)
This virtual function is called when something has been disconnected from signal in this object...
Definition: qobject.cpp:3162
unsigned short ushort
Definition: qglobal.h:995
static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connection *c, void **argv)
Definition: qobject.cpp:3459
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static int indexOfSlotRelative(const QMetaObject **m, const char *slot, bool normalizeStringData)
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
ExtraData * extraData
Definition: qobject_p.h:194
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
static void activate(QObject *sender, int signal_index, void **argv)
Definition: qobject.cpp:3690
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QList< QByteArray > dynamicPropertyNames() const
Returns the names of all properties that were dynamically added to the object using setProperty()...
Definition: qobject.cpp:3839
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual void placeMetaCall(QObject *object)
Definition: qobject.cpp:521
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
static bool check_parent_thread(QObject *parent, QThreadData *parentThreadData, QThreadData *currentThreadData)
Definition: qobject.cpp:718
static void(* parentChanged)(QAbstractDeclarativeData *, QObject *, QObject *)
Definition: qobject_p.h:94
#define QSLOT_CODE
Definition: qobjectdefs.h:243
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
The QMutexPool class provides a pool of QMutex objects.
Definition: qmutexpool_p.h:64
The QHash::iterator class provides an STL-style non-const iterator for QHash and QMultiHash.
Definition: qhash.h:330
const QMetaObject * superdata
Definition: qobjectdefs.h:469
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
QMetaObject * metaObject
Definition: qobject.h:107
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition: qobject_p.h:93
QString objectName() const
struct QMetaObject::@38 d
QVariant read(const QObject *obj) const
Reads the property&#39;s value from the given object.
QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set
void dumpObjectInfo()
Dumps information about signal connections, etc.
Definition: qobject.cpp:3917
static bool disconnectOne(const QObject *sender, int signal_index, const QObject *receiver, int method_index)
Definition: qobject.cpp:3290
static int * queuedConnectionTypes(const QList< QByteArray > &typeNames)
Definition: qobject.cpp:73
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
static QThreadData * current()
int attributes() const
bool isReadable() const
Returns true if this property is readable; otherwise returns false.
static bool disconnect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, DisconnectType=DisconnectAll)
Definition: qobject.cpp:3342
quint16 index
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
QObject * parent
Definition: qobject.h:92
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
void dumpObjectTree()
Dumps a tree of children to the debug output.
Definition: qobject.cpp:3901
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QObjectPrivate::ConnectionList & operator[](int at)
Definition: qobject.cpp:266
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
QObject * currentChildBeingDeleted
Definition: qobject_p.h:213
virtual ~QObjectData()=0
Definition: qobject.cpp:131
static void removeGuard(QObject **ptr)
Definition: qobject.cpp:406
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
removePostedEvents
Removes all events of the given eventType that were posted using postEvent() for receiver.
const QMetaObject * mobj
Definition: qmetaobject.h:139
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
uint sendChildEvents
Definition: qobject.h:100
QThread * thread() const
Returns the thread in which the object lives.
Definition: qobject.cpp:1419
void setThreadData_helper(QThreadData *currentData, QThreadData *targetData)
Definition: qobject.cpp:1524
static const QMetaObjectPrivate * get(const QMetaObject *metaobject)
bool write(QObject *obj, const QVariant &value) const
Writes value as the property&#39;s value to the given object.
QObjectList receiverList(const char *signal) const
Definition: qobject.cpp:298
uint pendTimer
Definition: qobject.h:96
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
friend class QThreadData
Definition: qobject.h:330
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
int postedEvents
Definition: qobject.h:106
static const KeyPair *const end
const char * qFlagLocation(const char *method)
Definition: qobject.cpp:2222
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
static int extract_code(const char *member)
Definition: qobject.cpp:2228
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QThread * thread
Definition: qthread_p.h:260
StaticMetaCallFunction callFunction
Definition: qobject_p.h:118
#define qPrintable(string)
Definition: qglobal.h:1750
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static void check_and_warn_compat(const QMetaObject *sender, const QMetaMethod &signal, const QMetaObject *receiver, const QMetaMethod &method)
Definition: qobject.cpp:2497
The QThread class provides a platform-independent way to manage threads.
Definition: qthread.h:59
int signalId() const
Definition: qobject_p.h:303
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QAbstractEventDispatcher * eventDispatcher
Definition: qthread_p.h:264
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
#define QT_TRY
Definition: qglobal.h:1536
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
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.
Definition: qobject.h:162
iterator erase(iterator it)
Removes the (key, value) pair associated with the iterator pos from the hash, and returns an iterator...
Definition: qhash.h:827
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
uint receiveChildEvents
Definition: qobject.h:101
virtual bool unregisterTimers(QObject *object)=0
Unregisters all the timers associated with the given object.
QObjectConnectionListVector * connectionLists
Definition: qobject_p.h:197
The QAbstractEventDispatcher class provides an interface to manage Qt&#39;s event queue.
QObject * qt_qFindChild_helper(const QObject *parent, const QString &name, const QMetaObject &mo)
Definition: qobject.cpp:1924
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
Definition: qobject_p.h:219
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
QMetaProperty property(int index) const
Returns the meta-data for the property with the given index.
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...
int signalIndex(const char *signalName) const
Returns the signal index used in the internal connectionLists vector.
Definition: qobject.cpp:3719
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480