summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/kernel.pri2
-rw-r--r--src/corelib/kernel/qabstracteventdispatcher.h4
-rw-r--r--src/corelib/kernel/qabstractnativeeventfilter.h4
-rw-r--r--src/corelib/kernel/qbasictimer.h4
-rw-r--r--src/corelib/kernel/qcore_mac_p.h15
-rw-r--r--src/corelib/kernel/qcore_unix.cpp21
-rw-r--r--src/corelib/kernel/qcore_unix_p.h54
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp232
-rw-r--r--src/corelib/kernel/qcoreapplication.h72
-rw-r--r--src/corelib/kernel/qcoreapplication_p.h46
-rw-r--r--src/corelib/kernel/qcoreapplication_win.cpp8
-rw-r--r--src/corelib/kernel/qcoreevent.h4
-rw-r--r--src/corelib/kernel/qeventdispatcher_blackberry.cpp18
-rw-r--r--src/corelib/kernel/qeventdispatcher_blackberry_p.h2
-rw-r--r--src/corelib/kernel/qeventdispatcher_glib.cpp6
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix.cpp51
-rw-r--r--src/corelib/kernel/qeventdispatcher_unix_p.h11
-rw-r--r--src/corelib/kernel/qeventloop.h4
-rw-r--r--src/corelib/kernel/qeventloop_p.h4
-rw-r--r--src/corelib/kernel/qfunctions_nacl.h8
-rw-r--r--src/corelib/kernel/qfunctions_p.h3
-rw-r--r--src/corelib/kernel/qfunctions_vxworks.cpp10
-rw-r--r--src/corelib/kernel/qfunctions_vxworks.h56
-rw-r--r--src/corelib/kernel/qfunctions_wince.h6
-rw-r--r--src/corelib/kernel/qmath.cpp87
-rw-r--r--src/corelib/kernel/qmath.h28
-rw-r--r--src/corelib/kernel/qmath.qdoc6
-rw-r--r--src/corelib/kernel/qmetaobject.cpp10
-rw-r--r--src/corelib/kernel/qmetaobject.h4
-rw-r--r--src/corelib/kernel/qmetatype.cpp8
-rw-r--r--src/corelib/kernel/qmetatype.h37
-rw-r--r--src/corelib/kernel/qmetatype_p.h2
-rw-r--r--src/corelib/kernel/qmimedata.h4
-rw-r--r--src/corelib/kernel/qobject.cpp83
-rw-r--r--src/corelib/kernel/qobject.h42
-rw-r--r--src/corelib/kernel/qobject_impl.h7
-rw-r--r--src/corelib/kernel/qobject_p.h77
-rw-r--r--src/corelib/kernel/qobjectcleanuphandler.h4
-rw-r--r--src/corelib/kernel/qobjectdefs.h4
-rw-r--r--src/corelib/kernel/qobjectdefs_impl.h49
-rw-r--r--src/corelib/kernel/qpointer.cpp1
-rw-r--r--src/corelib/kernel/qpointer.h100
-rw-r--r--src/corelib/kernel/qsharedmemory.h4
-rw-r--r--src/corelib/kernel/qsharedmemory_p.h2
-rw-r--r--src/corelib/kernel/qsharedmemory_unix.cpp3
-rw-r--r--src/corelib/kernel/qsignalmapper.h4
-rw-r--r--src/corelib/kernel/qsocketnotifier.h4
-rw-r--r--src/corelib/kernel/qsystemerror_p.h6
-rw-r--r--src/corelib/kernel/qsystemsemaphore.h4
-rw-r--r--src/corelib/kernel/qsystemsemaphore_win.cpp2
-rw-r--r--src/corelib/kernel/qtimer.h6
-rw-r--r--src/corelib/kernel/qtimerinfo_unix.cpp85
-rw-r--r--src/corelib/kernel/qtimerinfo_unix_p.h14
-rw-r--r--src/corelib/kernel/qtranslator.h4
-rw-r--r--src/corelib/kernel/qvariant.cpp10
-rw-r--r--src/corelib/kernel/qvariant.h30
-rw-r--r--src/corelib/kernel/qvariant_p.h2
-rw-r--r--src/corelib/kernel/qwineventnotifier.h4
58 files changed, 939 insertions, 443 deletions
diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri
index 34e32a721d..5a8499d723 100644
--- a/src/corelib/kernel/kernel.pri
+++ b/src/corelib/kernel/kernel.pri
@@ -131,7 +131,7 @@ unix|integrity {
contains(QT_CONFIG, clock-gettime):include($$QT_SOURCE_TREE/config.tests/unix/clock-gettime/clock-gettime.pri)
- !linux-android-* {
+ !android {
SOURCES += kernel/qsharedmemory_unix.cpp \
kernel/qsystemsemaphore_unix.cpp
} else {
diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h
index c07c395a84..6f21cefa4e 100644
--- a/src/corelib/kernel/qabstracteventdispatcher.h
+++ b/src/corelib/kernel/qabstracteventdispatcher.h
@@ -45,8 +45,6 @@
#include <QtCore/qobject.h>
#include <QtCore/qeventloop.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QAbstractNativeEventFilter;
@@ -129,6 +127,4 @@ protected:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QABSTRACTEVENTDISPATCHER_H
diff --git a/src/corelib/kernel/qabstractnativeeventfilter.h b/src/corelib/kernel/qabstractnativeeventfilter.h
index 09701a4923..9d1db2c19b 100644
--- a/src/corelib/kernel/qabstractnativeeventfilter.h
+++ b/src/corelib/kernel/qabstractnativeeventfilter.h
@@ -44,8 +44,6 @@
#include <QtCore/qnamespace.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QAbstractNativeEventFilterPrivate;
@@ -65,6 +63,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif /* QABSTRACTNATIVEEVENTFILTER_H */
diff --git a/src/corelib/kernel/qbasictimer.h b/src/corelib/kernel/qbasictimer.h
index 4fdb00d633..432e4d58c8 100644
--- a/src/corelib/kernel/qbasictimer.h
+++ b/src/corelib/kernel/qbasictimer.h
@@ -45,8 +45,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qnamespace.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -70,6 +68,4 @@ Q_DECLARE_TYPEINFO(QBasicTimer, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QBASICTIMER_H
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index c3a3afaf6c..4211a23e0f 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -57,12 +57,14 @@
# define __IMAGECAPTURE__
#endif
-#if defined(QT_BUILD_QMAKE) || defined(QT_BOOTSTRAPPED)
+#if defined(QT_BOOTSTRAPPED)
#include <ApplicationServices/ApplicationServices.h>
#else
#include <CoreFoundation/CoreFoundation.h>
#endif
+#include "qglobal.h"
+
#ifndef Q_OS_IOS
#include <CoreServices/CoreServices.h>
#endif
@@ -106,6 +108,7 @@ public:
return *this;
}
inline T *operator&() { return &type; }
+ template <typename X> X as() const { return reinterpret_cast<X>(type); }
static QCFType constructFromGet(const T &t)
{
CFRetain(t);
@@ -136,14 +139,4 @@ private:
QT_END_NAMESPACE
-#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
-#ifndef __LP64__
- typedef float CGFloat;
- typedef int NSInteger;
- typedef unsigned int NSUInteger;
- #define SRefCon SInt32
- #define URefCon UInt32
-#endif
-#endif
-
#endif // QCORE_MAC_P_H
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp
index cc5479876d..241658acb1 100644
--- a/src/corelib/kernel/qcore_unix.cpp
+++ b/src/corelib/kernel/qcore_unix.cpp
@@ -60,8 +60,8 @@
QT_BEGIN_NAMESPACE
-static inline bool time_update(struct timeval *tv, const struct timeval &start,
- const struct timeval &timeout)
+static inline bool time_update(struct timespec *tv, const struct timespec &start,
+ const struct timespec &timeout)
{
if (!QElapsedTimer::isMonotonic()) {
// we cannot recalculate the timeout without a monotonic clock as the time may have changed
@@ -69,13 +69,13 @@ static inline bool time_update(struct timeval *tv, const struct timeval &start,
}
// clock source is monotonic, so we can recalculate how much timeout is left
- struct timeval now = qt_gettime();
+ struct timespec now = qt_gettime();
*tv = timeout + start - now;
return tv->tv_sec >= 0;
}
int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
- const struct timeval *orig_timeout)
+ const struct timespec *orig_timeout)
{
if (!orig_timeout) {
// no timeout -> block forever
@@ -84,13 +84,20 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
return ret;
}
- timeval start = qt_gettime();
- timeval timeout = *orig_timeout;
+ timespec start = qt_gettime();
+ timespec timeout = *orig_timeout;
// loop and recalculate the timeout as needed
int ret;
forever {
- ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeout);
+#ifndef Q_OS_QNX
+ ret = ::pselect(nfds, fdread, fdwrite, fdexcept, &timeout, 0);
+#else
+ timeval timeoutVal;
+ timeoutVal.tv_sec = timeout.tv_sec;
+ timeoutVal.tv_usec = timeout.tv_nsec / 1000;
+ ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeoutVal);
+#endif
if (ret != -1 || errno != EINTR)
return ret;
diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h
index 6342b0362a..b68146cd6c 100644
--- a/src/corelib/kernel/qcore_unix_p.h
+++ b/src/corelib/kernel/qcore_unix_p.h
@@ -100,49 +100,49 @@ using namespace QT_PREPEND_NAMESPACE(QtLibcSupplement);
QT_BEGIN_NAMESPACE
-// Internal operator functions for timevals
-inline timeval &normalizedTimeval(timeval &t)
+// Internal operator functions for timespecs
+inline timespec &normalizedTimespec(timespec &t)
{
- while (t.tv_usec >= 1000000) {
+ while (t.tv_nsec >= 1000000000) {
++t.tv_sec;
- t.tv_usec -= 1000000;
+ t.tv_nsec -= 1000000000;
}
- while (t.tv_usec < 0) {
+ while (t.tv_nsec < 0) {
--t.tv_sec;
- t.tv_usec += 1000000;
+ t.tv_nsec += 1000000000;
}
return t;
}
-inline bool operator<(const timeval &t1, const timeval &t2)
-{ return t1.tv_sec < t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_usec < t2.tv_usec); }
-inline bool operator==(const timeval &t1, const timeval &t2)
-{ return t1.tv_sec == t2.tv_sec && t1.tv_usec == t2.tv_usec; }
-inline timeval &operator+=(timeval &t1, const timeval &t2)
+inline bool operator<(const timespec &t1, const timespec &t2)
+{ return t1.tv_sec < t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec < t2.tv_nsec); }
+inline bool operator==(const timespec &t1, const timespec &t2)
+{ return t1.tv_sec == t2.tv_sec && t1.tv_nsec == t2.tv_nsec; }
+inline timespec &operator+=(timespec &t1, const timespec &t2)
{
t1.tv_sec += t2.tv_sec;
- t1.tv_usec += t2.tv_usec;
- return normalizedTimeval(t1);
+ t1.tv_nsec += t2.tv_nsec;
+ return normalizedTimespec(t1);
}
-inline timeval operator+(const timeval &t1, const timeval &t2)
+inline timespec operator+(const timespec &t1, const timespec &t2)
{
- timeval tmp;
+ timespec tmp;
tmp.tv_sec = t1.tv_sec + t2.tv_sec;
- tmp.tv_usec = t1.tv_usec + t2.tv_usec;
- return normalizedTimeval(tmp);
+ tmp.tv_nsec = t1.tv_nsec + t2.tv_nsec;
+ return normalizedTimespec(tmp);
}
-inline timeval operator-(const timeval &t1, const timeval &t2)
+inline timespec operator-(const timespec &t1, const timespec &t2)
{
- timeval tmp;
+ timespec tmp;
tmp.tv_sec = t1.tv_sec - (t2.tv_sec - 1);
- tmp.tv_usec = t1.tv_usec - (t2.tv_usec + 1000000);
- return normalizedTimeval(tmp);
+ tmp.tv_nsec = t1.tv_nsec - (t2.tv_nsec + 1000000000);
+ return normalizedTimespec(tmp);
}
-inline timeval operator*(const timeval &t1, int mul)
+inline timespec operator*(const timespec &t1, int mul)
{
- timeval tmp;
+ timespec tmp;
tmp.tv_sec = t1.tv_sec * mul;
- tmp.tv_usec = t1.tv_usec * mul;
- return normalizedTimeval(tmp);
+ tmp.tv_nsec = t1.tv_nsec * mul;
+ return normalizedTimespec(tmp);
}
inline void qt_ignore_sigpipe()
@@ -335,11 +335,11 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options)
#endif
// in qelapsedtimer_mac.cpp or qtimestamp_unix.cpp
-timeval qt_gettime() Q_DECL_NOTHROW;
+timespec qt_gettime() Q_DECL_NOTHROW;
void qt_nanosleep(timespec amount);
Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept,
- const struct timeval *tv);
+ const struct timespec *tv);
// according to X/OPEN we have to define semun ourselves
// we use prefix as on some systems sem.h will have it
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index ec808424f9..cce8c30d81 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -42,9 +42,11 @@
#include "qcoreapplication.h"
#include "qcoreapplication_p.h"
+#ifndef QT_NO_QOBJECT
#include "qabstracteventdispatcher.h"
#include "qcoreevent.h"
#include "qeventloop.h"
+#endif
#include "qcorecmdlineargs_p.h"
#include <qdatastream.h>
#include <qdebug.h>
@@ -55,10 +57,12 @@
#include <private/qprocess_p.h>
#include <qstandardpaths.h>
#include <qtextcodec.h>
+#ifndef QT_NO_QOBJECT
#include <qthread.h>
#include <qthreadpool.h>
#include <qthreadstorage.h>
#include <private/qthread_p.h>
+#endif
#include <qelapsedtimer.h>
#include <qlibraryinfo.h>
#include <qvarlengtharray.h>
@@ -66,6 +70,7 @@
#include <private/qfunctions_p.h>
#include <private/qlocale_p.h>
+#ifndef QT_NO_QOBJECT
#if defined(Q_OS_UNIX)
# if defined(Q_OS_BLACKBERRY)
# include "qeventdispatcher_blackberry_p.h"
@@ -78,10 +83,10 @@
# include "qeventdispatcher_unix_p.h"
# endif
#endif
-
#ifdef Q_OS_WIN
# include "qeventdispatcher_win_p.h"
#endif
+#endif // QT_NO_QOBJECT
#ifdef Q_OS_MAC
# include "qcore_mac_p.h"
@@ -91,6 +96,7 @@
#ifdef Q_OS_UNIX
# include <locale.h>
+# include <unistd.h>
#endif
#ifdef Q_OS_VXWORKS
@@ -99,6 +105,7 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_QOBJECT
class QMutexUnlocker
{
public:
@@ -113,6 +120,7 @@ private:
QMutex *mtx;
};
+#endif
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
extern QString qAppFileName();
@@ -183,19 +191,47 @@ void QCoreApplicationPrivate::processCommandLineArguments()
// Support for introspection
+#ifndef QT_NO_QOBJECT
QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set = { 0, 0, 0, 0 };
void qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set)
{
qt_signal_spy_callback_set = callback_set;
}
+#endif
extern "C" void Q_CORE_EXPORT qt_startup_hook()
{
}
+typedef QList<QtStartUpFunction> QStartUpFuncList;
+Q_GLOBAL_STATIC(QStartUpFuncList, preRList)
typedef QList<QtCleanUpFunction> QVFuncList;
Q_GLOBAL_STATIC(QVFuncList, postRList)
+#ifndef QT_NO_QOBJECT
+static QBasicMutex globalPreRoutinesMutex;
+#endif
+
+/*!
+ \internal
+
+ Adds a global routine that will be called from the QCoreApplication
+ constructor. The public API is Q_COREAPP_STARTUP_FUNCTION.
+*/
+void qAddPreRoutine(QtStartUpFunction p)
+{
+ QStartUpFuncList *list = preRList();
+ if (!list)
+ return;
+ // Due to C++11 parallel dynamic initialization, this can be called
+ // from multiple threads.
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(&globalPreRoutinesMutex);
+#endif
+ if (QCoreApplication::instance())
+ p();
+ list->prepend(p); // in case QCoreApplication is re-created, see qt_call_pre_routines
+}
void qAddPostRoutine(QtCleanUpFunction p)
{
@@ -213,6 +249,21 @@ void qRemovePostRoutine(QtCleanUpFunction p)
list->removeAll(p);
}
+static void qt_call_pre_routines()
+{
+ QStartUpFuncList *list = preRList();
+ if (!list)
+ return;
+#ifndef QT_NO_THREAD
+ QMutexLocker locker(&globalPreRoutinesMutex);
+#endif
+ // Unlike qt_call_post_routines, we don't empty the list, because
+ // Q_COREAPP_STARTUP_FUNCTION is a macro, so the user expects
+ // the function to be executed every time QCoreApplication is created.
+ for (int i = 0; i < list->count(); ++i)
+ list->at(i)();
+}
+
void Q_CORE_EXPORT qt_call_post_routines()
{
QVFuncList *list = 0;
@@ -230,12 +281,15 @@ void Q_CORE_EXPORT qt_call_post_routines()
}
+// initialized in qcoreapplication and in qtextstream autotest when setlocale is called.
+static bool qt_locale_initialized = false;
+
+#ifndef QT_NO_QOBJECT
+
// app starting up if false
bool QCoreApplicationPrivate::is_app_running = false;
// app closing down if true
bool QCoreApplicationPrivate::is_app_closing = false;
-// initialized in qcoreapplication and in qtextstream autotest when setlocale is called.
-static bool qt_locale_initialized = false;
Q_CORE_EXPORT uint qGlobalPostedEventsCount()
{
@@ -243,14 +297,17 @@ Q_CORE_EXPORT uint qGlobalPostedEventsCount()
return currentThreadData->postEventList.size() - currentThreadData->postEventList.startOffset;
}
-QCoreApplication *QCoreApplication::self = 0;
QAbstractEventDispatcher *QCoreApplicationPrivate::eventDispatcher = 0;
-uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
#ifdef Q_OS_UNIX
Qt::HANDLE qt_application_thread_id = 0;
#endif
+#endif // QT_NO_QOBJECT
+
+QCoreApplication *QCoreApplication::self = 0;
+uint QCoreApplicationPrivate::attribs = (1 << Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
+
struct QCoreApplicationData {
QCoreApplicationData() {
#ifndef QT_NO_LIBRARY
@@ -261,13 +318,6 @@ struct QCoreApplicationData {
#ifndef QT_NO_LIBRARY
delete app_libpaths;
#endif
-
- // cleanup the QAdoptedThread created for the main() thread
- if (QCoreApplicationPrivate::theMainThread) {
- QThreadData *data = QThreadData::get2(QCoreApplicationPrivate::theMainThread);
- QCoreApplicationPrivate::theMainThread = 0;
- data->deref(); // deletes the data and the adopted thread
- }
}
#ifdef Q_OS_BLACKBERRY
@@ -309,20 +359,29 @@ struct QCoreApplicationData {
Q_GLOBAL_STATIC(QCoreApplicationData, coreappdata)
+#ifndef QT_NO_QOBJECT
static bool quitLockRefEnabled = true;
+#endif
QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint flags)
- : QObjectPrivate()
- , argc(aargc)
+ :
+#ifndef QT_NO_QOBJECT
+ QObjectPrivate(),
+#endif
+ argc(aargc)
, argv(aargv)
#ifdef Q_OS_WIN
, origArgc(aargc)
, origArgv(new char *[aargc])
#endif
, application_type(0)
+#ifndef QT_NO_QOBJECT
, in_exec(false)
, aboutToQuitEmitted(false)
, threadData_clean(false)
+#else
+ , q_ptr(0)
+#endif
{
app_compile_version = flags & 0xffffff;
static const char *const empty = "";
@@ -330,27 +389,35 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint
argc = 0;
argv = (char **)&empty; // ouch! careful with QCoreApplication::argv()!
}
+#ifdef Q_OS_WIN
+ qCopy(argv, argv + argc, origArgv);
+#endif
+
+#ifndef QT_NO_QOBJECT
QCoreApplicationPrivate::is_app_closing = false;
-#if defined(Q_OS_UNIX)
+# if defined(Q_OS_UNIX)
qt_application_thread_id = QThread::currentThreadId();
-#elif defined(Q_OS_WIN)
- qCopy(argv, argv + argc, origArgv);
-#endif
+# endif
// note: this call to QThread::currentThread() may end up setting theMainThread!
if (QThread::currentThread() != theMainThread)
qWarning("WARNING: QApplication was not created in the main() thread.");
+#endif
}
QCoreApplicationPrivate::~QCoreApplicationPrivate()
{
+#ifndef QT_NO_QOBJECT
cleanupThreadData();
+#endif
#ifdef Q_OS_WIN
delete [] origArgv;
#endif
}
+#ifndef QT_NO_QOBJECT
+
void QCoreApplicationPrivate::cleanupThreadData()
{
if (threadData && !threadData_clean) {
@@ -423,6 +490,8 @@ void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver)
}
#endif
+#endif // QT_NO_QOBJECT
+
void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths()
{
#ifndef QT_NO_LIBRARY
@@ -544,13 +613,18 @@ void QCoreApplicationPrivate::initLocale()
\internal
*/
QCoreApplication::QCoreApplication(QCoreApplicationPrivate &p)
+#ifdef QT_NO_QOBJECT
+ : d_ptr(&p)
+#else
: QObject(p, 0)
+#endif
{
init();
// note: it is the subclasses' job to call
// QCoreApplicationPrivate::eventDispatcher->startingUp();
}
+#ifndef QT_NO_QOBJECT
/*!
Flushes the platform specific event queues.
@@ -567,6 +641,7 @@ void QCoreApplication::flush()
if (self && self->d_func()->eventDispatcher)
self->d_func()->eventDispatcher->flush();
}
+#endif
/*!
Constructs a Qt kernel application. Kernel applications are
@@ -587,16 +662,23 @@ QCoreApplication::QCoreApplication(int &argc, char **argv
, int _internal
#endif
)
+#ifdef QT_NO_QOBJECT
+ : d_ptr(new QCoreApplicationPrivate(argc, argv, _internal))
+#else
: QObject(*new QCoreApplicationPrivate(argc, argv, _internal))
+#endif
{
init();
+#ifndef QT_NO_QOBJECT
QCoreApplicationPrivate::eventDispatcher->startingUp();
+#endif
}
// ### move to QCoreApplicationPrivate constructor?
void QCoreApplication::init()
{
+ d_ptr->q_ptr = this;
Q_D(QCoreApplication);
QCoreApplicationPrivate::initLocale();
@@ -604,6 +686,7 @@ void QCoreApplication::init()
Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object");
QCoreApplication::self = this;
+#ifndef QT_NO_QOBJECT
// use the event dispatcher created by the app programmer (if any)
if (!QCoreApplicationPrivate::eventDispatcher)
QCoreApplicationPrivate::eventDispatcher = d->threadData->eventDispatcher;
@@ -618,17 +701,20 @@ void QCoreApplication::init()
}
d->threadData->eventDispatcher = QCoreApplicationPrivate::eventDispatcher;
+#endif
#ifndef QT_NO_LIBRARY
if (coreappdata()->app_libpaths)
d->appendApplicationPathToLibraryPaths();
#endif
+#ifndef QT_NO_QOBJECT
#if defined(Q_OS_UNIX) && !(defined(QT_NO_PROCESS))
// Make sure the process manager thread object is created in the main
// thread.
QProcessPrivate::initializeProcessManager();
#endif
+#endif
#ifdef QT_EVAL
extern void qt_core_eval_init(uint);
@@ -637,7 +723,12 @@ void QCoreApplication::init()
d->processCommandLineArguments();
+ qt_call_pre_routines();
qt_startup_hook();
+
+#ifndef QT_NO_QOBJECT
+ QCoreApplicationPrivate::is_app_running = true; // No longer starting up.
+#endif
}
/*!
@@ -648,8 +739,10 @@ QCoreApplication::~QCoreApplication()
qt_call_post_routines();
self = 0;
+#ifndef QT_NO_QOBJECT
QCoreApplicationPrivate::is_app_closing = true;
QCoreApplicationPrivate::is_app_running = false;
+#endif
#if !defined(QT_NO_THREAD)
// Synchronize and stop the global thread pool threads.
@@ -663,10 +756,12 @@ QCoreApplication::~QCoreApplication()
globalThreadPool->waitForDone();
#endif
+#ifndef QT_NO_QOBJECT
d_func()->threadData->eventDispatcher = 0;
if (QCoreApplicationPrivate::eventDispatcher)
QCoreApplicationPrivate::eventDispatcher->closingDown();
QCoreApplicationPrivate::eventDispatcher = 0;
+#endif
#ifndef QT_NO_LIBRARY
delete coreappdata()->app_libpaths;
@@ -708,6 +803,8 @@ bool QCoreApplication::testAttribute(Qt::ApplicationAttribute attribute)
}
+#ifndef QT_NO_QOBJECT
+
/*!
\property QCoreApplication::quitLockEnabled
@@ -1570,6 +1667,8 @@ void QCoreApplication::quit()
\sa quit()
*/
+#endif // QT_NO_QOBJECT
+
#ifndef QT_NO_TRANSLATION
/*!
Adds the translation file \a translationFile to the list of
@@ -1611,8 +1710,11 @@ bool QCoreApplication::installTranslator(QTranslator *translationFile)
return false;
#endif
+#ifndef QT_NO_QOBJECT
QEvent ev(QEvent::LanguageChange);
QCoreApplication::sendEvent(self, &ev);
+#endif
+
return true;
}
@@ -1634,10 +1736,12 @@ bool QCoreApplication::removeTranslator(QTranslator *translationFile)
return false;
QCoreApplicationPrivate *d = self->d_func();
if (d->translators.removeAll(translationFile)) {
+#ifndef QT_NO_QOBJECT
if (!self->closingDown()) {
QEvent ev(QEvent::LanguageChange);
QCoreApplication::sendEvent(self, &ev);
}
+#endif
return true;
}
return false;
@@ -1748,6 +1852,19 @@ bool QCoreApplicationPrivate::isTranslatorInstalled(QTranslator *translator)
&& QCoreApplication::self->d_func()->translators.contains(translator);
}
+#else
+
+QString QCoreApplication::translate(const char *context, const char *sourceText,
+ const char *disambiguation, int n)
+{
+ Q_UNUSED(context)
+ Q_UNUSED(disambiguation)
+ QString ret = QString::fromUtf8(sourceText);
+ if (n >= 0)
+ ret.replace(QLatin1String("%n"), QString::number(n));
+ return ret;
+}
+
#endif //QT_NO_TRANSLATE
/*!
@@ -1999,9 +2116,23 @@ QStringList QCoreApplication::arguments()
\sa organizationDomain, applicationName
*/
+/*!
+ \fn void QCoreApplication::organizationNameChanged()
+ \internal
+
+ While not useful from C++ due to how organizationName is normally set once on
+ startup, this is still needed for QML so that bindings are reevaluated after
+ that initial change.
+*/
void QCoreApplication::setOrganizationName(const QString &orgName)
{
+ if (coreappdata()->orgName == orgName)
+ return;
coreappdata()->orgName = orgName;
+#ifndef QT_NO_QOBJECT
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->organizationNameChanged();
+#endif
}
QString QCoreApplication::organizationName()
@@ -2027,9 +2158,21 @@ QString QCoreApplication::organizationName()
\sa organizationName, applicationName, applicationVersion
*/
+/*!
+ \fn void QCoreApplication::organizationDomainChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setOrganizationDomain(const QString &orgDomain)
{
+ if (coreappdata()->orgDomain == orgDomain)
+ return;
coreappdata()->orgDomain = orgDomain;
+#ifndef QT_NO_QOBJECT
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->organizationDomainChanged();
+#endif
}
QString QCoreApplication::organizationDomain()
@@ -2049,9 +2192,21 @@ QString QCoreApplication::organizationDomain()
\sa organizationName, organizationDomain, applicationVersion, applicationFilePath
*/
+/*!
+ \fn void QCoreApplication::applicationNameChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setApplicationName(const QString &application)
{
+ if (coreappdata()->application == application)
+ return;
coreappdata()->application = application;
+#ifndef QT_NO_QOBJECT
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->applicationNameChanged();
+#endif
}
QString QCoreApplication::applicationName()
@@ -2078,9 +2233,21 @@ Q_CORE_EXPORT QString qt_applicationName_noFallback()
\sa applicationName, organizationName, organizationDomain
*/
+/*!
+ \fn void QCoreApplication::applicationVersionChanged()
+ \internal
+
+ Primarily for QML, see organizationNameChanged.
+*/
void QCoreApplication::setApplicationVersion(const QString &version)
{
+ if (coreappdata()->applicationVersion == version)
+ return;
coreappdata()->applicationVersion = version;
+#ifndef QT_NO_QOBJECT
+ if (QCoreApplication::self)
+ emit QCoreApplication::self->applicationVersionChanged();
+#endif
}
QString QCoreApplication::applicationVersion()
@@ -2229,6 +2396,8 @@ void QCoreApplication::removeLibraryPath(const QString &path)
#endif //QT_NO_LIBRARY
+#ifndef QT_NO_QOBJECT
+
/*!
Installs an event filter \a filterObj for all native events
received by the application in the main thread.
@@ -2324,6 +2493,33 @@ void QCoreApplication::setEventDispatcher(QAbstractEventDispatcher *eventDispatc
mainThread->setEventDispatcher(eventDispatcher);
}
+#endif // QT_NO_QOBJECT
+
+/*!
+ \macro Q_COREAPP_STARTUP_FUNCTION(QtStartUpFunction ptr)
+ \since 5.1
+ \relates QCoreApplication
+ \reentrant
+
+ Adds a global function that will be called from the QCoreApplication
+ constructor. This macro is normally used to initialize libraries
+ for program-wide functionality, without requiring the application to
+ call into the library for initialization.
+
+ The function specified by \a ptr should take no arguments and should
+ return nothing. For example:
+
+ \snippet code/src_corelib_kernel_qcoreapplication.cpp 3
+
+ Note that the startup function will run at the end of the QCoreApplication constructor,
+ before any GUI initialization. If GUI code is required in the function,
+ use a timer (or a queued invocation) to perform the initialization later on,
+ from the event loop.
+
+ If QCoreApplication is deleted and another QCoreApplication is created,
+ the startup function will be invoked again.
+*/
+
/*!
\fn void qAddPostRoutine(QtCleanUpFunction ptr)
\relates QCoreApplication
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index 0a87689ff3..ae17aeec0e 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -42,15 +42,21 @@
#ifndef QCOREAPPLICATION_H
#define QCOREAPPLICATION_H
+#include <QtCore/qglobal.h>
+#include <QtCore/qstring.h>
+#ifndef QT_NO_QOBJECT
#include <QtCore/qobject.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/qeventloop.h>
+#else
+#include <QtCore/qscopedpointer.h>
+#endif
+#ifndef QT_NO_QOBJECT
#if defined(Q_OS_WIN) && !defined(tagMSG)
typedef struct tagMSG MSG;
#endif
-
-QT_BEGIN_HEADER
+#endif
QT_BEGIN_NAMESPACE
@@ -65,14 +71,19 @@ class QAbstractNativeEventFilter;
#define qApp QCoreApplication::instance()
-class Q_CORE_EXPORT QCoreApplication : public QObject
+class Q_CORE_EXPORT QCoreApplication
+#ifndef QT_NO_QOBJECT
+ : public QObject
+#endif
{
+#ifndef QT_NO_QOBJECT
Q_OBJECT
- Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName)
- Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion)
- Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName)
- Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain)
+ Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged)
+ Q_PROPERTY(QString applicationVersion READ applicationVersion WRITE setApplicationVersion NOTIFY applicationVersionChanged)
+ Q_PROPERTY(QString organizationName READ organizationName WRITE setOrganizationName NOTIFY organizationNameChanged)
+ Q_PROPERTY(QString organizationDomain READ organizationDomain WRITE setOrganizationDomain NOTIFY organizationDomainChanged)
Q_PROPERTY(bool quitLockEnabled READ isQuitLockEnabled WRITE setQuitLockEnabled)
+#endif
Q_DECLARE_PRIVATE(QCoreApplication)
public:
@@ -103,6 +114,7 @@ public:
static QCoreApplication *instance() { return self; }
+#ifndef QT_NO_QOBJECT
static int exec();
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
@@ -120,6 +132,7 @@ public:
static bool startingUp();
static bool closingDown();
+#endif
static QString applicationDirPath();
static QString applicationFilePath();
@@ -148,6 +161,7 @@ public:
{ return translate(context, key, disambiguation, n); }
#endif
+#ifndef QT_NO_QOBJECT
static void flush();
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj);
@@ -166,17 +180,29 @@ Q_SIGNALS:
#endif
);
+ void organizationNameChanged();
+ void organizationDomainChanged();
+ void applicationNameChanged();
+ void applicationVersionChanged();
+
protected:
bool event(QEvent *);
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
+#endif // QT_NO_QOBJECT
protected:
QCoreApplication(QCoreApplicationPrivate &p);
+#ifdef QT_NO_QOBJECT
+ QScopedPointer<QCoreApplicationPrivate> d_ptr;
+#endif
+
private:
+#ifndef QT_NO_QOBJECT
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
bool notifyInternal(QObject *receiver, QEvent *event);
+#endif
void init();
@@ -184,7 +210,6 @@ private:
Q_DISABLE_COPY(QCoreApplication)
- friend class QEventDispatcherUNIXPrivate;
friend class QApplication;
friend class QApplicationPrivate;
friend class QGuiApplication;
@@ -193,46 +218,59 @@ private:
friend class QWidget;
friend class QWidgetWindow;
friend class QWidgetPrivate;
+#ifndef QT_NO_QOBJECT
+ friend class QEventDispatcherUNIXPrivate;
friend class QCocoaEventDispatcherPrivate;
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
+#endif
friend Q_CORE_EXPORT QString qAppName();
friend class QClassFactory;
};
+#ifndef QT_NO_QOBJECT
inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
{ if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
{ if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
+#endif
-#ifdef QT_NO_TRANSLATION
-inline QString QCoreApplication::translate(const char *, const char *sourceText, const char *, int)
-{
- return QString::fromUtf8(sourceText);
-}
+#ifdef QT_NO_DEPRECATED
+# define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context)
+#else
+# define QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
+ QT_DEPRECATED static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0, int n = -1) \
+ { return QCoreApplication::translate(#context, sourceText, disambiguation, n); }
#endif
#define Q_DECLARE_TR_FUNCTIONS(context) \
public: \
static inline QString tr(const char *sourceText, const char *disambiguation = 0, int n = -1) \
{ return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
- QT_DEPRECATED static inline QString trUtf8(const char *sourceText, const char *disambiguation = 0, int n = -1) \
- { return QCoreApplication::translate(#context, sourceText, disambiguation, n); } \
+ QT_DECLARE_DEPRECATED_TR_FUNCTIONS(context) \
private:
+typedef void (*QtStartUpFunction)();
typedef void (*QtCleanUpFunction)();
+Q_CORE_EXPORT void qAddPreRoutine(QtStartUpFunction);
Q_CORE_EXPORT void qAddPostRoutine(QtCleanUpFunction);
Q_CORE_EXPORT void qRemovePostRoutine(QtCleanUpFunction);
Q_CORE_EXPORT QString qAppName(); // get application name
+#define Q_COREAPP_STARTUP_FUNCTION(AFUNC) \
+ static void AFUNC ## _ctor_function() { \
+ qAddPreRoutine(AFUNC); \
+ } \
+ Q_CONSTRUCTOR_FUNCTION(AFUNC ## _ctor_function)
+
+#ifndef QT_NO_QOBJECT
#if defined(Q_OS_WIN) && !defined(QT_NO_DEBUG_STREAM)
Q_CORE_EXPORT QString decodeMSG(const MSG &);
Q_CORE_EXPORT QDebug operator<<(QDebug, const MSG &);
#endif
+#endif
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QCOREAPPLICATION_H
diff --git a/src/corelib/kernel/qcoreapplication_p.h b/src/corelib/kernel/qcoreapplication_p.h
index 36ba0663b7..563a3b2093 100644
--- a/src/corelib/kernel/qcoreapplication_p.h
+++ b/src/corelib/kernel/qcoreapplication_p.h
@@ -56,7 +56,9 @@
#include "QtCore/qcoreapplication.h"
#include "QtCore/qtranslator.h"
#include "QtCore/qsettings.h"
+#ifndef QT_NO_QOBJECT
#include "private/qobject_p.h"
+#endif
QT_BEGIN_NAMESPACE
@@ -64,7 +66,10 @@ typedef QList<QTranslator*> QTranslatorList;
class QAbstractEventDispatcher;
-class Q_CORE_EXPORT QCoreApplicationPrivate : public QObjectPrivate
+class Q_CORE_EXPORT QCoreApplicationPrivate
+#ifndef QT_NO_QOBJECT
+ : public QObjectPrivate
+#endif
{
Q_DECLARE_PUBLIC(QCoreApplication)
@@ -77,23 +82,27 @@ public:
QCoreApplicationPrivate(int &aargc, char **aargv, uint flags);
~QCoreApplicationPrivate();
+ QString appName() const;
+
+#ifdef Q_OS_MAC
+ static QString macMenuBarName();
+#endif
+
+ static void initLocale();
+
+ static bool checkInstance(const char *method);
+
+#ifndef QT_NO_QOBJECT
bool sendThroughApplicationEventFilters(QObject *, QEvent *);
bool sendThroughObjectEventFilters(QObject *, QEvent *);
bool notify_helper(QObject *, QEvent *);
- QString appName() const;
virtual void createEventDispatcher();
static void removePostedEvent(QEvent *);
#ifdef Q_OS_WIN
static void removePostedTimerEvent(QObject *object, int timerId);
#endif
-#ifdef Q_OS_MAC
- static QString macMenuBarName();
-#endif
-
- static void initLocale();
-
QAtomicInt quitLockRef;
void ref();
void deref();
@@ -104,12 +113,14 @@ public:
static QThread *theMainThread;
static QThread *mainThread();
- static bool checkInstance(const char *method);
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
#if !defined (QT_NO_DEBUG) || defined (QT_MAC_FRAMEWORK_BUILD)
void checkReceiverThread(QObject *receiver);
#endif
+ void cleanupThreadData();
+#endif // QT_NO_QOBJECT
+
int &argc;
char **argv;
#ifdef Q_OS_WIN
@@ -117,24 +128,27 @@ public:
char **origArgv; // store unmodified arguments for QCoreApplication::arguments()
#endif
void appendApplicationPathToLibraryPaths(void);
- void cleanupThreadData();
#ifndef QT_NO_TRANSLATION
QTranslatorList translators;
+
+ static bool isTranslatorInstalled(QTranslator *translator);
#endif
+
uint application_type;
- bool in_exec;
- bool aboutToQuitEmitted;
- bool threadData_clean;
QString cachedApplicationDirPath;
QString cachedApplicationFilePath;
- static bool isTranslatorInstalled(QTranslator *translator);
+#ifndef QT_NO_QOBJECT
+ bool in_exec;
+ bool aboutToQuitEmitted;
+ bool threadData_clean;
static QAbstractEventDispatcher *eventDispatcher;
static bool is_app_running;
static bool is_app_closing;
+#endif
static uint attribs;
static inline bool testAttribute(uint flag) { return attribs & (1 << flag); }
@@ -143,6 +157,10 @@ public:
void processCommandLineArguments();
QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging.
inline QString qmljsDebugArgumentsString() { return qmljs_debug_arguments; }
+
+#ifdef QT_NO_QOBJECT
+ QCoreApplication *q_ptr;
+#endif
};
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp
index 3cb89e8fcd..93e45d3984 100644
--- a/src/corelib/kernel/qcoreapplication_win.cpp
+++ b/src/corelib/kernel/qcoreapplication_win.cpp
@@ -43,10 +43,12 @@
#include "qcoreapplication_p.h"
#include "qstringlist.h"
#include "qvector.h"
-#include "qmutex.h"
#include "qfileinfo.h"
#include "qcorecmdlineargs_p.h"
+#ifndef QT_NO_QOBJECT
+#include "qmutex.h"
#include <private/qthread_p.h>
+#endif
#include <ctype.h>
#include <qt_windows.h>
@@ -157,6 +159,8 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
Q_UNUSED(prevInstance);
}
+#ifndef QT_NO_QOBJECT
+
void QCoreApplicationPrivate::removePostedTimerEvent(QObject *object, int timerId)
{
QThreadData *data = object->d_func()->threadData;
@@ -996,4 +1000,6 @@ QDebug operator<<(QDebug dbg, const MSG &msg)
}
#endif
+#endif // QT_NO_QOBJECT
+
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h
index d35b5198a9..47a461d330 100644
--- a/src/corelib/kernel/qcoreevent.h
+++ b/src/corelib/kernel/qcoreevent.h
@@ -46,8 +46,6 @@
#include <QtCore/qbytearray.h>
#include <QtCore/qobjectdefs.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -377,6 +375,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QCOREEVENT_H
diff --git a/src/corelib/kernel/qeventdispatcher_blackberry.cpp b/src/corelib/kernel/qeventdispatcher_blackberry.cpp
index 3e958ee277..5206334c09 100644
--- a/src/corelib/kernel/qeventdispatcher_blackberry.cpp
+++ b/src/corelib/kernel/qeventdispatcher_blackberry.cpp
@@ -271,13 +271,13 @@ void QEventDispatcherBlackberry::unregisterSocketNotifier(QSocketNotifier *notif
}
}
-static inline int timevalToMillisecs(const timeval &tv)
+static inline int timespecToMillisecs(const timespec &tv)
{
- return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
+ return (tv.tv_sec * 1000) + (tv.tv_nsec / 1000000);
}
int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- timeval *timeout)
+ timespec *timeout)
{
Q_UNUSED(nfds);
Q_D(QEventDispatcherBlackberry);
@@ -306,9 +306,9 @@ int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writef
// Convert timeout to milliseconds
int timeoutTotal = -1;
if (timeout)
- timeoutTotal = timevalToMillisecs(*timeout);
+ timeoutTotal = timespecToMillisecs(*timeout);
int timeoutLeft = timeoutTotal;
- timeval startTime = qt_gettime();
+ timespec startTime = qt_gettime();
// This loop exists such that we can drain the bps event queue of all native events
// more efficiently than if we were to return control to Qt after each event. This
@@ -332,16 +332,16 @@ int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writef
// Update the timeout
// Clock source is monotonic, so we can recalculate how much timeout is left
if (timeoutTotal != -1) {
- timeval t2 = qt_gettime();
+ timespec t2 = qt_gettime();
timeoutLeft = timeoutTotal
- - (timevalToMillisecs(t2) - timevalToMillisecs(startTime));
+ - (timespecToMillisecs(t2) - timespecToMillisecs(startTime));
if (timeoutLeft < 0)
timeoutLeft = 0;
}
- timeval tnext;
+ timespec tnext;
if (d->timerList.timerWait(tnext)) {
- int timeoutNext = timevalToMillisecs(tnext);
+ int timeoutNext = timespecToMillisecs(tnext);
if (timeoutNext < timeoutLeft || timeoutTotal == -1) {
timeoutTotal = timeoutLeft = timeoutNext;
startTime = qt_gettime();
diff --git a/src/corelib/kernel/qeventdispatcher_blackberry_p.h b/src/corelib/kernel/qeventdispatcher_blackberry_p.h
index 79ed21dbf2..5a4c3a9dcd 100644
--- a/src/corelib/kernel/qeventdispatcher_blackberry_p.h
+++ b/src/corelib/kernel/qeventdispatcher_blackberry_p.h
@@ -77,7 +77,7 @@ protected:
QEventDispatcherBlackberry(QEventDispatcherBlackberryPrivate &dd, QObject *parent = 0);
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- timeval *timeout);
+ timespec *timeout);
int ioEvents(int fd);
};
diff --git a/src/corelib/kernel/qeventdispatcher_glib.cpp b/src/corelib/kernel/qeventdispatcher_glib.cpp
index c6680d6a80..17830868da 100644
--- a/src/corelib/kernel/qeventdispatcher_glib.cpp
+++ b/src/corelib/kernel/qeventdispatcher_glib.cpp
@@ -131,9 +131,9 @@ struct GTimerSource
static gboolean timerSourcePrepareHelper(GTimerSource *src, gint *timeout)
{
- timeval tv = { 0l, 0l };
+ timespec tv = { 0l, 0l };
if (!(src->processEventsFlags & QEventLoop::X11ExcludeTimers) && src->timerList.timerWait(tv))
- *timeout = (tv.tv_sec * 1000) + ((tv.tv_usec + 999) / 1000);
+ *timeout = (tv.tv_sec * 1000) + ((tv.tv_nsec + 999999) / 1000 / 1000);
else
*timeout = -1;
@@ -293,12 +293,14 @@ static GSourceFuncs postEventSourceFuncs = {
QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(GMainContext *context)
: mainContext(context)
{
+#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 32
if (qEnvironmentVariableIsEmpty("QT_NO_THREADED_GLIB")) {
static QBasicMutex mutex;
QMutexLocker locker(&mutex);
if (!g_thread_supported())
g_thread_init(NULL);
}
+#endif
if (mainContext) {
g_main_context_ref(mainContext);
diff --git a/src/corelib/kernel/qeventdispatcher_unix.cpp b/src/corelib/kernel/qeventdispatcher_unix.cpp
index acdc7635e8..c79fe89105 100644
--- a/src/corelib/kernel/qeventdispatcher_unix.cpp
+++ b/src/corelib/kernel/qeventdispatcher_unix.cpp
@@ -56,6 +56,10 @@
#include <stdio.h>
#include <stdlib.h>
+#ifndef QT_NO_EVENTFD
+# include <sys/eventfd.h>
+#endif
+
// VxWorks doesn't correctly set the _POSIX_... options
#if defined(Q_OS_VXWORKS)
# if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK <= 0)
@@ -109,7 +113,7 @@ QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate()
}
#elif defined(Q_OS_VXWORKS)
char name[20];
- qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdCurrent));
+ qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf()));
// make sure there is no pipe with this name
pipeDevDelete(name, true);
@@ -127,6 +131,12 @@ QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate()
}
}
#else
+# ifndef QT_NO_EVENTFD
+ thread_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+ if (thread_pipe[0] != -1)
+ thread_pipe[1] = -1;
+ else // fall through the next "if"
+# endif
if (qt_safe_pipe(thread_pipe, O_NONBLOCK) == -1) {
perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe");
pipefail = true;
@@ -149,20 +159,21 @@ QEventDispatcherUNIXPrivate::~QEventDispatcherUNIXPrivate()
close(thread_pipe[0]);
char name[20];
- qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdCurrent));
+ qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf()));
pipeDevDelete(name, true);
#else
// cleanup the common parts of the event loop
close(thread_pipe[0]);
- close(thread_pipe[1]);
+ if (thread_pipe[1] != -1)
+ close(thread_pipe[1]);
#endif
// cleanup timers
qDeleteAll(timerList);
}
-int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, timeval *timeout)
+int QEventDispatcherUNIXPrivate::doSelect(QEventLoop::ProcessEventsFlags flags, timespec *timeout)
{
Q_Q(QEventDispatcherUNIX);
@@ -279,9 +290,18 @@ int QEventDispatcherUNIXPrivate::processThreadWakeUp(int nsel)
::read(thread_pipe[0], c, sizeof(c));
::ioctl(thread_pipe[0], FIOFLUSH, 0);
#else
- char c[16];
- while (::read(thread_pipe[0], c, sizeof(c)) > 0)
- ;
+# ifndef QT_NO_EVENTFD
+ if (thread_pipe[1] == -1) {
+ // eventfd
+ eventfd_t value;
+ eventfd_read(thread_pipe[0], &value);
+ } else
+# endif
+ {
+ char c[16];
+ while (::read(thread_pipe[0], c, sizeof(c)) > 0) {
+ }
+ }
#endif
if (!wakeUps.testAndSetRelease(1, 0)) {
// hopefully, this is dead code
@@ -307,7 +327,7 @@ QEventDispatcherUNIX::~QEventDispatcherUNIX()
}
int QEventDispatcherUNIX::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- timeval *timeout)
+ timespec *timeout)
{
return qt_safe_select(nfds, readfds, writefds, exceptfds, timeout);
}
@@ -580,8 +600,8 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
if (!d->interrupt) {
// return the maximum time we can wait for an event.
- timeval *tm = 0;
- timeval wait_tm = { 0l, 0l };
+ timespec *tm = 0;
+ timespec wait_tm = { 0l, 0l };
if (!(flags & QEventLoop::X11ExcludeTimers)) {
if (d->timerList.timerWait(wait_tm))
tm = &wait_tm;
@@ -593,7 +613,7 @@ bool QEventDispatcherUNIX::processEvents(QEventLoop::ProcessEventsFlags flags)
// no time to wait
tm->tv_sec = 0l;
- tm->tv_usec = 0l;
+ tm->tv_nsec = 0l;
}
nevents = d->doSelect(flags, tm);
@@ -630,6 +650,15 @@ void QEventDispatcherUNIX::wakeUp()
{
Q_D(QEventDispatcherUNIX);
if (d->wakeUps.testAndSetAcquire(0, 1)) {
+#ifndef QT_NO_EVENTFD
+ if (d->thread_pipe[1] == -1) {
+ // eventfd
+ eventfd_t value = 1;
+ int ret;
+ EINTR_LOOP(ret, eventfd_write(d->thread_pipe[0], value));
+ return;
+ }
+#endif
char c = 0;
qt_safe_write( d->thread_pipe[1], &c, 1 );
}
diff --git a/src/corelib/kernel/qeventdispatcher_unix_p.h b/src/corelib/kernel/qeventdispatcher_unix_p.h
index afebe2fb7e..db89b7c444 100644
--- a/src/corelib/kernel/qeventdispatcher_unix_p.h
+++ b/src/corelib/kernel/qeventdispatcher_unix_p.h
@@ -61,9 +61,7 @@
#include "QtCore/qvarlengtharray.h"
#include "private/qtimerinfo_unix_p.h"
-#if defined(Q_OS_VXWORKS)
-# include <sys/times.h>
-#else
+#if !defined(Q_OS_VXWORKS)
# include <sys/time.h>
# if (!defined(Q_OS_HPUX) || defined(__ia64)) && !defined(Q_OS_NACL)
# include <sys/select.h>
@@ -132,7 +130,7 @@ protected:
virtual int select(int nfds,
fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
- timeval *timeout);
+ timespec *timeout);
};
class Q_CORE_EXPORT QEventDispatcherUNIXPrivate : public QAbstractEventDispatcherPrivate
@@ -143,11 +141,14 @@ public:
QEventDispatcherUNIXPrivate();
~QEventDispatcherUNIXPrivate();
- int doSelect(QEventLoop::ProcessEventsFlags flags, timeval *timeout);
+ int doSelect(QEventLoop::ProcessEventsFlags flags, timespec *timeout);
virtual int initThreadWakeUp();
virtual int processThreadWakeUp(int nsel);
bool mainThread;
+
+ // note for eventfd(7) support:
+ // if thread_pipe[1] is -1, then eventfd(7) is in use and is stored in thread_pipe[0]
int thread_pipe[2];
// highest fd for all socket notifiers
diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h
index d4141a05bc..926be08265 100644
--- a/src/corelib/kernel/qeventloop.h
+++ b/src/corelib/kernel/qeventloop.h
@@ -44,8 +44,6 @@
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -106,6 +104,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QEVENTLOOP_H
diff --git a/src/corelib/kernel/qeventloop_p.h b/src/corelib/kernel/qeventloop_p.h
index 21a1dcda4c..8e2bfdb55e 100644
--- a/src/corelib/kernel/qeventloop_p.h
+++ b/src/corelib/kernel/qeventloop_p.h
@@ -44,8 +44,6 @@
#include "qobject_p.h"
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QEventLoopPrivate : public QObjectPrivate
@@ -76,6 +74,4 @@ public:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QEVENTLOOP_P_H
diff --git a/src/corelib/kernel/qfunctions_nacl.h b/src/corelib/kernel/qfunctions_nacl.h
index 2cb9d16c95..c15b9756d0 100644
--- a/src/corelib/kernel/qfunctions_nacl.h
+++ b/src/corelib/kernel/qfunctions_nacl.h
@@ -42,6 +42,8 @@
#ifndef QFUNCTIONS_NACL_H
#define QFUNCTIONS_NACL_H
+#include <QtCore/qglobal.h>
+
#ifdef Q_OS_NACL
#include <sys/types.h>
@@ -52,8 +54,6 @@
#define PTHREAD_CANCEL_ENABLE 2
#define PTHREAD_INHERIT_SCHED 3
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -69,7 +69,7 @@ int pthread_cancel(pthread_t thread);
int pthread_attr_setinheritsched(pthread_attr_t *attr,
int inheritsched);
-int pthread_attr_getinheritsched(const pthread_attr_t *attr,
+int pthread_attr_getinheritsched(const pthread_attr_t *attr,
int *inheritsched);
// event dispatcher, select
@@ -89,8 +89,6 @@ int select(int nfds, fd_set * readfds, fd_set * writefds, fd_set * errorfds, str
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif //Q_OS_NACL
#endif //QFUNCTIONS_NACL_H
diff --git a/src/corelib/kernel/qfunctions_p.h b/src/corelib/kernel/qfunctions_p.h
index 57c6a8f295..6e094f1ed3 100644
--- a/src/corelib/kernel/qfunctions_p.h
+++ b/src/corelib/kernel/qfunctions_p.h
@@ -72,8 +72,5 @@
# define Q_STATIC_GLOBAL_INLINE_OPERATOR static inline
#endif
-QT_BEGIN_HEADER
-QT_END_HEADER
-
#endif
diff --git a/src/corelib/kernel/qfunctions_vxworks.cpp b/src/corelib/kernel/qfunctions_vxworks.cpp
index 2174588757..e1abecb9d6 100644
--- a/src/corelib/kernel/qfunctions_vxworks.cpp
+++ b/src/corelib/kernel/qfunctions_vxworks.cpp
@@ -46,7 +46,9 @@
#include "qplatformdefs.h"
#include "qfunctions_vxworks.h"
+#if defined(_WRS_KERNEL)
#include <vmLib.h>
+#endif
#include <selectLib.h>
#include <ioLib.h>
@@ -74,10 +76,12 @@ void *lfind(const void* key, const void* base, size_t* elements, size_t size,
// no rand_r(), but rand()
// NOTE: this implementation is wrong for multi threaded applications,
// but there is no way to get it right on VxWorks (in kernel mode)
+#if defined(_WRS_KERNEL)
int rand_r(unsigned int * /*seedp*/)
{
return rand();
}
+#endif
// no usleep() support
int usleep(unsigned int usec)
@@ -92,7 +96,7 @@ int usleep(unsigned int usec)
// gettimeofday() is declared, but is missing from the library
// It IS however defined in the Curtis-Wright X11 libraries, so
// we have to make the symbol 'weak'
-#if defined(Q_CC_DIAB)
+#if defined(Q_CC_DIAB) && !defined(VXWORKS_DKM) && !defined(VXWORKS_RTP)
# pragma weak gettimeofday
#endif
int gettimeofday(struct timeval *tv, void /*struct timezone*/ *)
@@ -118,7 +122,11 @@ int gettimeofday(struct timeval *tv, void /*struct timezone*/ *)
// neither getpagesize() or sysconf(_SC_PAGESIZE) are available
int getpagesize()
{
+#if defined(_WRS_KERNEL)
return vmPageSizeGet();
+#else
+ return sysconf(_SC_PAGESIZE);
+#endif
}
// symlinks are not supported (lstat is now just a call to stat - see qplatformdefs.h)
diff --git a/src/corelib/kernel/qfunctions_vxworks.h b/src/corelib/kernel/qfunctions_vxworks.h
index 6339903cff..e33401a86a 100644
--- a/src/corelib/kernel/qfunctions_vxworks.h
+++ b/src/corelib/kernel/qfunctions_vxworks.h
@@ -41,6 +41,9 @@
#ifndef QFUNCTIONS_VXWORKS_H
#define QFUNCTIONS_VXWORKS_H
+
+#include <QtCore/qglobal.h>
+
#ifdef Q_OS_VXWORKS
#include <unistd.h>
@@ -52,7 +55,11 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
+#if defined(_WRS_KERNEL)
#include <sys/times.h>
+#else
+#include <sys/time.h>
+#endif
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -61,15 +68,50 @@
#include <net/if.h>
#endif
-QT_BEGIN_HEADER
+// VxWorks has public header mbuf.h which defines following variables for DKM.
+// Let's undef those to because they overlap with Qt variable names-
+// File mbuf.h is included in headers <netinet/in.h> <net/if.h>, so make sure
+// that those are included before undef's.
+#if defined(mbuf)
+# undef mbuf
+#endif
+#if defined(m_data)
+# undef m_data
+#endif
+#if defined(m_type)
+# undef m_type
+#endif
+#if defined(m_next)
+# undef m_next
+#endif
+#if defined(m_len)
+# undef m_len
+#endif
+#if defined(m_flags)
+# undef m_flags
+#endif
+#if defined(m_hdr)
+# undef m_hdr
+#endif
+#if defined(m_ext)
+# undef m_ext
+#endif
+#if defined(m_act)
+# undef m_act
+#endif
+#if defined(m_nextpkt)
+# undef m_nextpkt
+#endif
+#if defined(m_pkthdr)
+# undef m_pkthdr
+#endif
+
QT_BEGIN_NAMESPACE
#ifdef QT_BUILD_CORE_LIB
#endif
QT_END_NAMESPACE
-QT_END_HEADER
-
#ifndef RTLD_LOCAL
#define RTLD_LOCAL 0
@@ -95,17 +137,23 @@ void *lfind(const void* key, const void* base, size_t* elements, size_t size,
// no rand_r(), but rand()
// NOTE: this implementation is wrong for multi threaded applications,
// but there is no way to get it right on VxWorks (in kernel mode)
+#if defined(_WRS_KERNEL)
int rand_r(unsigned int * /*seedp*/);
+#endif
// no usleep() support
int usleep(unsigned int);
+#if defined(VXWORKS_DKM) || defined(VXWORKS_RTP)
+int gettimeofday(struct timeval *, void *);
+#else
// gettimeofday() is declared, but is missing from the library.
// It IS however defined in the Curtis-Wright X11 libraries, so
// we have to make the symbol 'weak'
int gettimeofday(struct timeval *tv, void /*struct timezone*/ *) __attribute__((weak));
+#endif
-// neither getpagesize() or sysconf(_SC_PAGESIZE) are available
+// getpagesize() not available
int getpagesize();
// symlinks are not supported (lstat is now just a call to stat - see qplatformdefs.h)
diff --git a/src/corelib/kernel/qfunctions_wince.h b/src/corelib/kernel/qfunctions_wince.h
index e20a4ceaca..ab7bbe3f99 100644
--- a/src/corelib/kernel/qfunctions_wince.h
+++ b/src/corelib/kernel/qfunctions_wince.h
@@ -41,6 +41,9 @@
#ifndef QFUNCTIONS_WINCE_H
#define QFUNCTIONS_WINCE_H
+
+#include <QtCore/qglobal.h>
+
#ifdef Q_OS_WINCE
#include <stdio.h>
#include <stdlib.h>
@@ -56,15 +59,12 @@
#include <winsock.h>
#include <ceconfig.h>
-QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
#ifdef QT_BUILD_CORE_LIB
#endif
QT_END_NAMESPACE
-QT_END_HEADER
-
// The standard SDK misses this define...
#define _control87 _controlfp
diff --git a/src/corelib/kernel/qmath.cpp b/src/corelib/kernel/qmath.cpp
index 1d6fcc2cd6..8f900e2101 100644
--- a/src/corelib/kernel/qmath.cpp
+++ b/src/corelib/kernel/qmath.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -302,4 +303,90 @@ const qreal qt_sine_table[QT_SINE_TABLE_SIZE] = {
qreal(-0.024541228522912448)
};
+/*!
+ \headerfile <QtMath>
+ \title Generic Math Declarations
+ \ingroup funclists
+
+ \brief The <QtMath> header file includes generic math declarations.
+
+ The global declarations include \l{functions}.
+
+ These functions are partly convenience definitions for basic
+ operations, for instance not available in the Standard Template Library et
+ al.
+*/
+
+/*!
+ \fn float qDegreesToRadians(float degrees)
+ \relates <QtMath>
+ \since 5.1
+
+ \brief The function converts the \a degrees in float to radians.
+
+ The purpose of the function is to aid the conversion as such a convenient
+ function is not part of the Standard Template Library, i.e. in <cmath> or
+ elsewhere.
+
+ Example:
+
+ \snippet code/src_corelib_kernel_qmath.cpp 0
+
+ \sa qRadiansToDegrees()
+*/
+
+/*!
+ \fn double qDegreesToRadians(double degrees)
+ \relates <QtMath>
+ \since 5.1
+
+ \brief The function converts the \a degrees in double to radians.
+
+ The purpose of the function is to aid the conversion as such a convenient
+ function is not part of the Standard Template Library, i.e. in <cmath> or
+ elsewhere.
+
+ Example:
+
+ \snippet code/src_corelib_kernel_qmath.cpp 1
+
+ \sa qRadiansToDegrees()
+*/
+
+/*!
+ \fn float qRadiansToDegrees(float radians)
+ \relates <QtMath>
+ \since 5.1
+
+ \brief The function converts the \a radians in float to degrees.
+
+ The purpose of the function is to aid the conversion as such a convenient
+ function is not part of the Standard Template Library, i.e. in <cmath> or
+ elsewhere.
+
+ Example:
+
+ \snippet code/src_corelib_kernel_qmath.cpp 2
+
+ \sa qDegreesToRadians()
+*/
+
+/*!
+ \fn double qRadiansToDegrees(double radians)
+ \relates <QtMath>
+ \since 5.1
+
+ \brief The function converts the \a radians in double to degrees.
+
+ The purpose of the function is to aid the conversion as such a convenient
+ function is not part of the Standard Template Library, i.e. in <cmath> or
+ elsewhere.
+
+ Example:
+
+ \snippet code/src_corelib_kernel_qmath.cpp 3
+
+ \sa qDegreesToRadians()
+*/
+
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h
index 097200d690..21e23b9eb0 100644
--- a/src/corelib/kernel/qmath.h
+++ b/src/corelib/kernel/qmath.h
@@ -42,12 +42,14 @@
#ifndef QMATH_H
#define QMATH_H
+#if 0
+#pragma qt_class(QtMath)
+#endif
+
#include <math.h>
#include <QtCore/qglobal.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -264,8 +266,26 @@ inline qreal qFastCos(qreal x)
return qt_sine_table[si] - (qt_sine_table[ci] + 0.5 * qt_sine_table[si] * d) * d;
}
-QT_END_NAMESPACE
+Q_DECL_CONSTEXPR inline float qDegreesToRadians(float degrees)
+{
+ return degrees * float(M_PI/180);
+}
+
+Q_DECL_CONSTEXPR inline double qDegreesToRadians(double degrees)
+{
+ return degrees * (M_PI / 180);
+}
+
+Q_DECL_CONSTEXPR inline float qRadiansToDegrees(float radians)
+{
+ return radians * float(180/M_PI);
+}
-QT_END_HEADER
+Q_DECL_CONSTEXPR inline double qRadiansToDegrees(double radians)
+{
+ return radians * (180 / M_PI);
+}
+
+QT_END_NAMESPACE
#endif // QMATH_H
diff --git a/src/corelib/kernel/qmath.qdoc b/src/corelib/kernel/qmath.qdoc
index 448b167662..06d8db9277 100644
--- a/src/corelib/kernel/qmath.qdoc
+++ b/src/corelib/kernel/qmath.qdoc
@@ -25,7 +25,7 @@
**
****************************************************************************/
-/*!
+/*!
\headerfile <QtCore/qmath.h>
\title Math Functions
\ingroup funclists
@@ -35,11 +35,11 @@
/*!
\fn int qCeil(qreal v)
- Return the ceiling of the value \a v.
+ Return the ceiling of the value \a v.
The ceiling is the smallest integer that is not less than \a v.
For example, if \a v is 41.2, then the ceiling is 42.
-
+
\relates <QtCore/qmath.h>
\sa qFloor()
*/
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index 14d96e96fd..4399349352 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -1001,7 +1001,7 @@ int QMetaObject::indexOfProperty(const char *name) const
Q_ASSERT(priv(this->d.data)->revision >= 3);
if (priv(this->d.data)->flags & DynamicMetaObject) {
- QAbstractDynamicMetaObject *me =
+ QAbstractDynamicMetaObject *me =
const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this));
return me->createProperty(name, 0);
@@ -2041,8 +2041,8 @@ QMetaMethod QMetaMethod::fromSignalImpl(const QMetaObject *metaObject, void **si
\snippet code/src_corelib_kernel_qmetaobject.cpp 8
- QMetaObject::normalizedSignature() is used here to ensure that the format
- of the signature is what invoke() expects. E.g. extra whitespace is
+ QMetaObject::normalizedSignature() is used here to ensure that the format
+ of the signature is what invoke() expects. E.g. extra whitespace is
removed.
If the "compute" slot does not take exactly one QString, one int
@@ -2970,7 +2970,7 @@ QMetaMethod QMetaProperty::notifySignal() const
{
int id = notifySignalIndex();
if (id != -1)
- return mobj->method(id);
+ return mobj->method(id);
else
return QMetaMethod();
}
@@ -2978,7 +2978,7 @@ QMetaMethod QMetaProperty::notifySignal() const
/*!
\since 4.6
- Returns the index of the property change notifying signal if one was
+ Returns the index of the property change notifying signal if one was
specified, otherwise returns -1.
\sa hasNotifySignal()
diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h
index 6d6b849d75..23fc89ffe3 100644
--- a/src/corelib/kernel/qmetaobject.h
+++ b/src/corelib/kernel/qmetaobject.h
@@ -45,8 +45,6 @@
#include <QtCore/qobjectdefs.h>
#include <QtCore/qvariant.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -274,6 +272,4 @@ Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QMETAOBJECT_H
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index abf220ebd4..b9f7462b12 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -959,11 +959,11 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
case QMetaType::QRegularExpression:
stream << *static_cast<const NS(QRegularExpression)*>(data);
break;
-#endif // QT_NO_REGEXP
+#endif // QT_NO_REGULAREXPRESSION
case QMetaType::QEasingCurve:
stream << *static_cast<const NS(QEasingCurve)*>(data);
break;
@@ -1182,11 +1182,11 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
break;
#endif
#ifndef QT_BOOTSTRAPPED
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
case QMetaType::QRegularExpression:
stream >> *static_cast< NS(QRegularExpression)*>(data);
break;
-#endif // QT_NO_REGEXP
+#endif // QT_NO_REGULAREXPRESSION
case QMetaType::QEasingCurve:
stream >> *static_cast< NS(QEasingCurve)*>(data);
break;
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h
index 3ffbfb8385..16ea1042a2 100644
--- a/src/corelib/kernel/qmetatype.h
+++ b/src/corelib/kernel/qmetatype.h
@@ -56,8 +56,6 @@
#error qmetatype.h must be included before any header file that defines Bool
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -534,6 +532,9 @@ struct QMetaTypeId2
static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return QMetaTypeId<T>::qt_metatype_id(); }
};
+template <typename T>
+struct QMetaTypeId2<const T&> : QMetaTypeId2<T> {};
+
namespace QtPrivate {
template <typename T, bool Defined = QMetaTypeId2<T>::Defined>
struct QMetaTypeIdHelper {
@@ -633,30 +634,30 @@ void qRegisterMetaTypeStreamOperators(const char *typeName
#endif // QT_NO_DATASTREAM
template <typename T>
-inline Q_DECL_CONSTEXPR int qMetaTypeId(
-#ifndef Q_QDOC
- T * /* dummy */ = 0
-#endif
-)
+inline Q_DECL_CONSTEXPR int qMetaTypeId()
{
Q_STATIC_ASSERT_X(QMetaTypeId2<T>::Defined, "Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system");
return QMetaTypeId2<T>::qt_metatype_id();
}
template <typename T>
-inline Q_DECL_CONSTEXPR int qRegisterMetaType(
-#if !defined(Q_QDOC) && !defined(Q_CC_SUN)
- T * dummy = 0
-#endif
-)
+inline Q_DECL_CONSTEXPR int qRegisterMetaType()
{
-#ifdef Q_CC_SUN
- return qMetaTypeId(static_cast<T *>(0));
-#else
- return qMetaTypeId(dummy);
-#endif
+ return qMetaTypeId<T>();
}
+#if QT_DEPRECATED_SINCE(5, 1) && !defined(Q_QDOC)
+// There used to be a T *dummy = 0 argument in Qt 4.0 to support MSVC6
+template <typename T>
+QT_DEPRECATED inline Q_DECL_CONSTEXPR int qMetaTypeId(T *)
+{ return qMetaTypeId<T>(); }
+#ifndef Q_CC_SUN
+template <typename T>
+QT_DEPRECATED inline Q_DECL_CONSTEXPR int qRegisterMetaType(T *)
+{ return qRegisterMetaType<T>(); }
+#endif
+#endif
+
template <typename T>
struct QMetaTypeIdQObject<T*, /* isPointerToTypeDerivedFromQObject */ true>
{
@@ -980,6 +981,4 @@ QT_END_NAMESPACE
QT_FOR_EACH_STATIC_TYPE(Q_DECLARE_BUILTIN_METATYPE)
-QT_END_HEADER
-
#endif // QMETATYPE_H
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index 39bdd5e3bb..95b9e2e394 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -221,7 +221,7 @@ template<> struct TypeDefinition<QPointF> { static const bool IsAvailable = fals
#ifdef QT_NO_REGEXP
template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
#endif
-#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGEXP)
+#if defined(QT_BOOTSTRAPPED) || defined(QT_NO_REGULAREXPRESSION)
template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
#endif
#ifdef QT_NO_SHORTCUT
diff --git a/src/corelib/kernel/qmimedata.h b/src/corelib/kernel/qmimedata.h
index 774a6e4986..84c73262b2 100644
--- a/src/corelib/kernel/qmimedata.h
+++ b/src/corelib/kernel/qmimedata.h
@@ -45,8 +45,6 @@
#include <QtCore/qvariant.h>
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -98,6 +96,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QMIMEDATA_H
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index a82242939d..1312e64d8b 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -927,7 +927,7 @@ QObjectPrivate::Connection::~Connection()
\relates QObject
Returns the given \a object cast to type T if the object is of type
- T (or of a subclass); otherwise returns 0. If \a object is 0 then
+ T (or of a subclass); otherwise returns 0. If \a object is 0 then
it will also return 0.
The class T must inherit (directly or indirectly) QObject and be
@@ -1690,7 +1690,7 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegExp &re,
}
#endif // QT_NO_REGEXP
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
/*!
\internal
*/
@@ -1712,7 +1712,7 @@ void qt_qFindChildren_helper(const QObject *parent, const QRegularExpression &re
qt_qFindChildren_helper(obj, re, mo, list, options);
}
}
-#endif // QT_NO_REGEXP
+#endif // QT_NO_REGULAREXPRESSION
/*!
\internal
@@ -3089,8 +3089,8 @@ bool QMetaObject::disconnect(const QObject *sender, int signal_index,
/*!
\internal
-Disconnect a single signal connection. If QMetaObject::connect() has been called
-multiple times for the same sender, signal_index, receiver and method_index only
+Disconnect a single signal connection. If QMetaObject::connect() has been called
+multiple times for the same sender, signal_index, receiver and method_index only
one of these connections will be removed.
*/
bool QMetaObject::disconnectOne(const QObject *sender, int signal_index,
@@ -3219,6 +3219,9 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender,
\snippet code/src_corelib_kernel_qobject.cpp 34
+ If \a object itself has a properly set object name, its own signals are also
+ connected to its respective slots.
+
\sa QObject::setObjectName()
*/
void QMetaObject::connectSlotsByName(QObject *o)
@@ -3227,39 +3230,66 @@ void QMetaObject::connectSlotsByName(QObject *o)
return;
const QMetaObject *mo = o->metaObject();
Q_ASSERT(mo);
- const QObjectList list = o->findChildren<QObject *>(QString());
+ const QObjectList list = // list of all objects to look for matching signals including...
+ o->findChildren<QObject *>(QString()) // all children of 'o'...
+ << o; // and the object 'o' itself
+
+ // for each method/slot of o ...
for (int i = 0; i < mo->methodCount(); ++i) {
- QByteArray slotSignature = mo->method(i).methodSignature();
+ const QByteArray slotSignature = mo->method(i).methodSignature();
const char *slot = slotSignature.constData();
Q_ASSERT(slot);
+
+ // ...that starts with "on_", ...
if (slot[0] != 'o' || slot[1] != 'n' || slot[2] != '_')
continue;
+
+ // ...we check each object in our list, ...
bool foundIt = false;
for(int j = 0; j < list.count(); ++j) {
const QObject *co = list.at(j);
- QByteArray objName = co->objectName().toLatin1();
- int len = objName.length();
- if (!len || qstrncmp(slot + 3, objName.data(), len) || slot[len+3] != '_')
+ const QByteArray coName = co->objectName().toLatin1();
+
+ // ...discarding those whose objectName is not fitting the pattern "on_<objectName>_...", ...
+ if (coName.isEmpty() || qstrncmp(slot + 3, coName.constData(), coName.size()) || slot[coName.size()+3] != '_')
continue;
+
+ const char *signal = slot + coName.size() + 4; // the 'signal' part of the slot name
+
+ // ...for the presence of a matching signal "on_<objectName>_<signal>".
const QMetaObject *smeta;
- int sigIndex = co->d_func()->signalIndex(slot + len + 4, &smeta);
- if (sigIndex < 0) { // search for compatible signals
+ int sigIndex = co->d_func()->signalIndex(signal, &smeta);
+ if (sigIndex < 0) {
+ // if no exactly fitting signal (name + complete parameter type list) could be found
+ // look for just any signal with the correct name and at least the slot's parameter list.
+ // Note: if more than one of thoses signals exist, the one that gets connected is
+ // chosen 'at random' (order of declaration in source file)
+ QList<QByteArray> compatibleSignals;
const QMetaObject *smo = co->metaObject();
- int slotlen = qstrlen(slot + len + 4) - 1;
- for (int k = 0; k < QMetaObjectPrivate::absoluteSignalCount(smo); ++k) {
- QMetaMethod method = QMetaObjectPrivate::signal(smo, k);
- if (!qstrncmp(method.methodSignature().constData(), slot + len + 4, slotlen)) {
+ int sigLen = qstrlen(signal) - 1; // ignore the trailing ')'
+ for (int k = QMetaObjectPrivate::absoluteSignalCount(smo)-1; k >= 0; --k) {
+ const QMetaMethod method = QMetaObjectPrivate::signal(smo, k);
+ if (!qstrncmp(method.methodSignature().constData(), signal, sigLen)) {
smeta = method.enclosingMetaObject();
sigIndex = k;
- break;
+ compatibleSignals.prepend(method.methodSignature());
}
}
+ if (compatibleSignals.size() > 1)
+ qWarning() << "QMetaObject::connectSlotsByName: Connecting slot" << slot
+ << "with the first of the following compatible signals:" << compatibleSignals;
}
+
if (sigIndex < 0)
continue;
+ // we connect it...
if (Connection(QMetaObjectPrivate::connect(co, sigIndex, smeta, o, i))) {
foundIt = true;
+ // ...and stop looking for further objects with the same name.
+ // Note: the Designer will make sure each object name is unique in the above
+ // 'list' but other code may create two child objects with the same name. In
+ // this case one is chosen 'at random'.
break;
}
}
@@ -3268,7 +3298,11 @@ void QMetaObject::connectSlotsByName(QObject *o)
while (mo->method(i + 1).attributes() & QMetaMethod::Cloned)
++i;
} else if (!(mo->method(i).attributes() & QMetaMethod::Cloned)) {
- qWarning("QMetaObject::connectSlotsByName: No matching signal for %s", slot);
+ // check if the slot has the following signature: "on_..._...(..."
+ int iParen = slotSignature.indexOf('(');
+ int iLastUnderscore = slotSignature.lastIndexOf('_', iParen-1);
+ if (iLastUnderscore > 3)
+ qWarning("QMetaObject::connectSlotsByName: No matching signal for %s", slot);
}
}
}
@@ -3334,7 +3368,7 @@ void QMetaObject::activate(QObject *sender, int signalOffset, int local_signal_i
return;
if (sender->d_func()->declarativeData && QAbstractDeclarativeData::signalEmitted)
- QAbstractDeclarativeData::signalEmitted(sender->d_func()->declarativeData, sender,
+ QAbstractDeclarativeData::signalEmitted(sender->d_func()->declarativeData, sender,
signal_index, argv);
void *empty_argv[] = { 0 };
@@ -4151,6 +4185,9 @@ void qDeleteInEventHandler(QObject *o)
\snippet code/src_corelib_kernel_qobject.cpp 25
make sure to declare the argument type with Q_DECLARE_METATYPE
+
+ \note The number of arguments in the signal or slot are limited to 6 if
+ the compiler does not support C++11 variadic templates.
*/
@@ -4181,6 +4218,10 @@ void qDeleteInEventHandler(QObject *o)
\snippet code/src_corelib_kernel_qobject.cpp 46
The connection will automatically disconnect if the sender is destroyed.
+
+ \note If the compiler does not support C++11 variadic templates, the number
+ of arguments in the signal or slot are limited to 6, and the functor object
+ must not have an overloaded or templated operator().
*/
/**
@@ -4194,7 +4235,7 @@ void qDeleteInEventHandler(QObject *o)
connecting to a static function or a functor
\a slot a pointer only used when using Qt::UniqueConnection
\a type the Qt::ConnctionType passed as argument to connect
- \a types an array of integer with the metatype id of the parametter of the signal
+ \a types an array of integer with the metatype id of the parameter of the signal
to be used with queued connection
must stay valid at least for the whole time of the connection, this function
do not take ownership. typically static data.
@@ -4209,7 +4250,7 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
const int *types, const QMetaObject *senderMetaObject)
{
if (!sender || !signal || !slotObj || !senderMetaObject) {
- qWarning("QObject::connect: invalid null parametter");
+ qWarning("QObject::connect: invalid null parameter");
if (slotObj)
slotObj->destroyIfLastRef();
return QMetaObject::Connection();
diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h
index a2d7dcd7ef..aaa09fac50 100644
--- a/src/corelib/kernel/qobject.h
+++ b/src/corelib/kernel/qobject.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -56,8 +57,6 @@
#include <QtCore/qobject_impl.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -73,7 +72,7 @@ class QWidget;
#ifndef QT_NO_REGEXP
class QRegExp;
#endif
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
class QRegularExpression;
#endif
#ifndef QT_NO_USERDATA
@@ -179,7 +178,7 @@ public:
}
#endif
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
template<typename T>
inline QList<T> findChildren(const QRegularExpression &re, Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
{
@@ -267,27 +266,50 @@ public:
static inline typename QtPrivate::QEnableIf<QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1, QMetaObject::Connection>::Type
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
{
+#if defined (Q_COMPILER_DECLTYPE) && defined (Q_COMPILER_VARIADIC_TEMPLATES)
+ typedef QtPrivate::FunctionPointer<Func1> SignalType;
+ const int FunctorArgumentCount = QtPrivate::ComputeFunctorArgumentCount<Func2 , typename SignalType::Arguments>::Value;
+
+ Q_STATIC_ASSERT_X((FunctorArgumentCount >= 0),
+ "Signal and slot arguments are not compatible.");
+ const int SlotArgumentCount = (FunctorArgumentCount >= 0) ? FunctorArgumentCount : 0;
+ typedef typename QtPrivate::FunctorReturnType<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotArgumentCount>::Value>::Value SlotReturnType;
+#else
+ // Without variadic template, we don't detect the best overload of operator(). We just
+ // assume there is only one simple operator() and connect to &Func2::operator()
+
+ /* If you get an error such as:
+ couldn't deduce template parameter 'Func2Operator'
+ or
+ cannot resolve address of overloaded function
+ It means the functor does not have a single operator().
+ Functors with overloaded or templated operator() are only supported if the compiler supports
+ C++11 variadic templates
+ */
#ifndef Q_COMPILER_DECLTYPE //Workaround the lack of decltype using another function as indirection
return connect_functor(sender, signal, slot, &Func2::operator()); }
template <typename Func1, typename Func2, typename Func2Operator>
static inline QMetaObject::Connection connect_functor(const QObject *sender, Func1 signal, Func2 slot, Func2Operator) {
typedef QtPrivate::FunctionPointer<Func2Operator> SlotType ;
#else
-
typedef QtPrivate::FunctionPointer<decltype(&Func2::operator())> SlotType ;
#endif
typedef QtPrivate::FunctionPointer<Func1> SignalType;
+ typedef typename SlotType::ReturnType SlotReturnType;
+ const int SlotArgumentCount = SlotType::ArgumentCount;
- Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
+ Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= SlotArgumentCount,
"The slot requires more arguments than the signal provides.");
Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
"Signal and slot arguments are not compatible.");
- Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename SlotType::ReturnType, typename SignalType::ReturnType>::value),
+#endif
+
+ Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<SlotReturnType, typename SignalType::ReturnType>::value),
"Return type of the slot is not compatible with the return type of the signal.");
return connectImpl(sender, reinterpret_cast<void **>(&signal), sender, 0,
- new QtPrivate::QFunctorSlotObject<Func2, SlotType::ArgumentCount,
- typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value,
+ new QtPrivate::QFunctorSlotObject<Func2, SlotArgumentCount,
+ typename QtPrivate::List_Left<typename SignalType::Arguments, SlotArgumentCount>::Value,
typename SignalType::ReturnType>(slot),
Qt::DirectConnection, 0, &SignalType::Object::staticMetaObject);
}
@@ -496,8 +518,6 @@ namespace QtPrivate {
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif
#endif // QOBJECT_H
diff --git a/src/corelib/kernel/qobject_impl.h b/src/corelib/kernel/qobject_impl.h
index 7ed4d33e96..0b5631f2a6 100644
--- a/src/corelib/kernel/qobject_impl.h
+++ b/src/corelib/kernel/qobject_impl.h
@@ -45,7 +45,10 @@
#error Do not include qobject_impl.h directly
#endif
-QT_BEGIN_HEADER
+#if 0
+#pragma qt_sync_skip_header_check
+#pragma qt_sync_stop_processing
+#endif
QT_BEGIN_NAMESPACE
@@ -207,6 +210,4 @@ namespace QtPrivate {
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index e4b4ce8b42..e849ec1599 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -198,6 +199,14 @@ public:
inline void connectNotify(const QMetaMethod &signal);
inline void disconnectNotify(const QMetaMethod &signal);
+ template <typename Func1, typename Func2>
+ static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
+ const typename QtPrivate::FunctionPointer<Func2>::Object *receiverPrivate, Func2 slot,
+ Qt::ConnectionType type = Qt::AutoConnection);
+
+ template <typename Func1, typename Func2>
+ static inline bool disconnect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
+ const typename QtPrivate::FunctionPointer<Func2>::Object *receiverPrivate, Func2 slot);
public:
ExtraData *extraData; // extra data set by the user
QThreadData *threadData; // id of the thread that owns the object
@@ -267,6 +276,74 @@ inline void QObjectPrivate::disconnectNotify(const QMetaMethod &signal)
q_ptr->disconnectNotify(signal);
}
+namespace QtPrivate {
+template<typename Func, typename Args, typename R> class QPrivateSlotObject : public QSlotObjectBase
+{
+ typedef QtPrivate::FunctionPointer<Func> FuncType;
+ Func function;
+ static void impl(int which, QSlotObjectBase *this_, QObject *r, void **a, bool *ret)
+ {
+ switch (which) {
+ case Destroy:
+ delete static_cast<QPrivateSlotObject*>(this_);
+ break;
+ case Call:
+ FuncType::template call<Args, R>(static_cast<QPrivateSlotObject*>(this_)->function,
+ static_cast<typename FuncType::Object *>(QObjectPrivate::get(r)), a);
+ break;
+ case Compare:
+ *ret = *reinterpret_cast<Func *>(a) == static_cast<QPrivateSlotObject*>(this_)->function;
+ break;
+ case NumOperations: ;
+ }
+ }
+public:
+ explicit QPrivateSlotObject(Func f) : QSlotObjectBase(&impl), function(f) {}
+};
+} //namespace QtPrivate
+
+template <typename Func1, typename Func2>
+inline QMetaObject::Connection QObjectPrivate::connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
+ const typename QtPrivate::FunctionPointer<Func2>::Object *receiverPrivate, Func2 slot,
+ Qt::ConnectionType type)
+{
+ typedef QtPrivate::FunctionPointer<Func1> SignalType;
+ typedef QtPrivate::FunctionPointer<Func2> SlotType;
+ reinterpret_cast<typename SignalType::Object *>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<typename SignalType::Object *>(0));
+
+ //compilation error if the arguments does not match.
+ Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
+ "The slot requires more arguments than the signal provides.");
+ Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
+ "Signal and slot arguments are not compatible.");
+ Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename SlotType::ReturnType, typename SignalType::ReturnType>::value),
+ "Return type of the slot is not compatible with the return type of the signal.");
+
+ const int *types = 0;
+ if (type == Qt::QueuedConnection || type == Qt::BlockingQueuedConnection)
+ types = QtPrivate::ConnectionTypes<typename SignalType::Arguments>::types();
+
+ return QObject::connectImpl(sender, reinterpret_cast<void **>(&signal),
+ receiverPrivate->q_func(), reinterpret_cast<void **>(&slot),
+ new QtPrivate::QPrivateSlotObject<Func2, typename QtPrivate::List_Left<typename SignalType::Arguments, SlotType::ArgumentCount>::Value,
+ typename SignalType::ReturnType>(slot),
+ type, types, &SignalType::Object::staticMetaObject);
+}
+
+template <typename Func1, typename Func2>
+bool QObjectPrivate::disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object* sender, Func1 signal,
+ const typename QtPrivate::FunctionPointer< Func2 >::Object* receiverPrivate, Func2 slot)
+{
+ typedef QtPrivate::FunctionPointer<Func1> SignalType;
+ typedef QtPrivate::FunctionPointer<Func2> SlotType;
+ reinterpret_cast<typename SignalType::Object *>(0)->qt_check_for_QOBJECT_macro(*reinterpret_cast<typename SignalType::Object *>(0));
+ //compilation error if the arguments does not match.
+ Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
+ "Signal and slot arguments are not compatible.");
+ return QObject::disconnectImpl(sender, reinterpret_cast<void **>(&signal),
+ receiverPrivate->q_func(), reinterpret_cast<void **>(&slot),
+ &SignalType::Object::staticMetaObject);
+}
Q_DECLARE_TYPEINFO(QObjectPrivate::Connection, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(QObjectPrivate::Sender, Q_MOVABLE_TYPE);
diff --git a/src/corelib/kernel/qobjectcleanuphandler.h b/src/corelib/kernel/qobjectcleanuphandler.h
index 96faabc173..1f053cc34b 100644
--- a/src/corelib/kernel/qobjectcleanuphandler.h
+++ b/src/corelib/kernel/qobjectcleanuphandler.h
@@ -44,8 +44,6 @@
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -72,6 +70,4 @@ private Q_SLOTS:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QOBJECTCLEANUPHANDLER_H
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index a0617379d5..afbe1a5ece 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -46,8 +46,6 @@
#include <QtCore/qobjectdefs_impl.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -483,6 +481,4 @@ inline const QMetaObject *QMetaObject::superClass() const
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QOBJECTDEFS_H
diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h
index 68d8fdf961..4f44d9204e 100644
--- a/src/corelib/kernel/qobjectdefs_impl.h
+++ b/src/corelib/kernel/qobjectdefs_impl.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -45,7 +46,10 @@
#error Do not include qobjectdefs_impl.h directly
#endif
-QT_BEGIN_HEADER
+#if 0
+#pragma qt_sync_skip_header_check
+#pragma qt_sync_stop_processing
+#endif
QT_BEGIN_NAMESPACE
@@ -59,7 +63,7 @@ namespace QtPrivate {
/*
The following List classes are used to help to handle the list of arguments.
It follow the same principles as the lisp lists.
- List_Left<L,N> take a list and a number as a parametter and returns (via the Value typedef,
+ List_Left<L,N> take a list and a number as a parameter and returns (via the Value typedef,
the list composed of the first N element of the list
*/
#ifndef Q_COMPILER_VARIADIC_TEMPLATES
@@ -90,7 +94,7 @@ namespace QtPrivate {
template <typename T>
struct ApplyReturnValue {
void *data;
- ApplyReturnValue(void *data_) : data(data_) {}
+ explicit ApplyReturnValue(void *data_) : data(data_) {}
};
template<typename T, typename U>
void operator,(const T &value, const ApplyReturnValue<U> &container) {
@@ -113,7 +117,7 @@ namespace QtPrivate {
- ArgumentCount is the number of argument, or -1 if it is unknown
- the Object typedef is the Object of a pointer to member function
- the Arguments typedef is the list of argument (in a QtPrivate::List)
- - the Function typedef is an alias to the template parametter Func
+ - the Function typedef is an alias to the template parameter Func
- the call<Args, R>(f,o,args) method is used to call that slot
Args is the list of argument of the signal
R is the return type of the signal
@@ -594,13 +598,44 @@ namespace QtPrivate {
enum { value = AreArgumentsCompatible<typename RemoveConstRef<Arg1>::Type, typename RemoveConstRef<Arg2>::Type>::value
&& CheckCompatibleArguments<List<Tail1...>, List<Tail2...>>::value };
};
+#endif
+
+#if defined(Q_COMPILER_DECLTYPE) && defined(Q_COMPILER_VARIADIC_TEMPLATES)
+ /*
+ Find the maximum number of arguments a functor object can take and be still compatible with
+ the arguments from the signal.
+ Value is the number of arguments, or -1 if nothing matches.
+ */
+ template <typename Functor, typename ArgList> struct ComputeFunctorArgumentCount;
+
+ template <typename Functor, typename ArgList, bool Done> struct ComputeFunctorArgumentCountHelper
+ { enum { Value = -1 }; };
+ template <typename Functor, typename First, typename... ArgList>
+ struct ComputeFunctorArgumentCountHelper<Functor, List<First, ArgList...>, false>
+ : ComputeFunctorArgumentCount<Functor,
+ typename List_Left<List<First, ArgList...>, sizeof...(ArgList)>::Value> {};
+
+ template <typename Functor, typename... ArgList> struct ComputeFunctorArgumentCount<Functor, List<ArgList...>>
+ {
+ template <typename D> static D dummy();
+ template <typename F> static auto test(F f) -> decltype(((f.operator()((dummy<ArgList>())...)), int()));
+ static char test(...);
+ enum {
+ Ok = sizeof(test(dummy<Functor>())) == sizeof(int),
+ Value = Ok ? sizeof...(ArgList) : int(ComputeFunctorArgumentCountHelper<Functor, List<ArgList...>, Ok>::Value)
+ };
+ };
+ /* get the return type of a functor, given the signal argument list */
+ template <typename Functor, typename ArgList> struct FunctorReturnType;
+ template <typename Functor, typename ... ArgList> struct FunctorReturnType<Functor, List<ArgList...>> {
+ template <typename D> static D dummy();
+ typedef decltype(dummy<Functor>().operator()((dummy<ArgList>())...)) Value;
+ };
#endif
-}
+}
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif
diff --git a/src/corelib/kernel/qpointer.cpp b/src/corelib/kernel/qpointer.cpp
index eea90be5eb..4fd6cd1779 100644
--- a/src/corelib/kernel/qpointer.cpp
+++ b/src/corelib/kernel/qpointer.cpp
@@ -158,6 +158,7 @@
/*!
\fn void QPointer::clear()
+ \since 5.0
Clears this QPointer object.
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index ebdeb156ba..230b6b66eb 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -46,67 +46,51 @@
#ifndef QT_NO_QOBJECT
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QVariant;
-class QPointerBase
-{
- QWeakPointer<QObject> wp;
-
-protected:
- inline QPointerBase() : wp() { }
- inline QPointerBase(QObject *p) : wp(p, true) { }
- // compiler-generated copy/move ctor/assignment operators are fine! (even though public)
- inline ~QPointerBase() { }
-
- inline QObject* data() const
- { return wp.data(); }
-
- inline void assign(QObject *p)
- { wp.assign(p); }
-
- inline bool isNull() const
- { return wp.isNull(); }
-
- inline void clear()
- { wp.clear(); }
-};
-
template <class T>
-class QPointer : private QPointerBase
+class QPointer
{
+ template<typename U>
+ struct TypeSelector
+ {
+ typedef QObject Type;
+ };
+ template<typename U>
+ struct TypeSelector<const U>
+ {
+ typedef const QObject Type;
+ };
+ typedef typename TypeSelector<T>::Type QObjectType;
+ QWeakPointer<QObjectType> wp;
public:
inline QPointer() { }
- inline QPointer(T *p) : QPointerBase(p) { }
+ inline QPointer(T *p) : wp(p, true) { }
// compiler-generated copy/move ctor/assignment operators are fine!
inline ~QPointer() { }
inline QPointer<T> &operator=(T* p)
- { QPointerBase::assign(p); return *this; }
+ { wp.assign(static_cast<QObjectType*>(p)); return *this; }
inline T* data() const
- { return static_cast<T*>(QPointerBase::data()); }
+ { return static_cast<T*>( wp.data()); }
inline T* operator->() const
{ return data(); }
inline T& operator*() const
{ return *data(); }
inline operator T*() const
{ return data(); }
-#ifdef Q_QDOC
- inline bool isNull() const;
- inline void clear();
-#else
- using QPointerBase::isNull;
- using QPointerBase::clear;
-#endif
+
+ inline bool isNull() const
+ { return wp.isNull(); }
+
+ inline void clear()
+ { wp.clear(); }
};
template <class T> Q_DECLARE_TYPEINFO_BODY(QPointer<T>, Q_MOVABLE_TYPE);
-#if (!defined(Q_CC_SUN) || (__SUNPRO_CC >= 0x580)) // ambiguity between const T * and T *
-
template <class T>
inline bool operator==(const T *o, const QPointer<T> &p)
{ return o == p.operator->(); }
@@ -115,18 +99,6 @@ template<class T>
inline bool operator==(const QPointer<T> &p, const T *o)
{ return p.operator->() == o; }
-#else
-
-template<class T>
-inline bool operator==(const void *o, const QPointer<T> &p)
-{ return o == p.operator->(); }
-
-template<class T>
-inline bool operator==(const QPointer<T> &p, const void *o)
-{ return p.operator->() == o; }
-
-#endif
-
template <class T>
inline bool operator==(T *o, const QPointer<T> &p)
{ return o == p.operator->(); }
@@ -139,9 +111,6 @@ template<class T>
inline bool operator==(const QPointer<T> &p1, const QPointer<T> &p2)
{ return p1.operator->() == p2.operator->(); }
-
-#if (!defined(Q_CC_SUN) || (__SUNPRO_CC >= 0x580)) // ambiguity between const T * and T *
-
template <class T>
inline bool operator!=(const T *o, const QPointer<T> &p)
{ return o != p.operator->(); }
@@ -150,18 +119,6 @@ template<class T>
inline bool operator!= (const QPointer<T> &p, const T *o)
{ return p.operator->() != o; }
-#else
-
-template<class T>
-inline bool operator!= (const void *o, const QPointer<T> &p)
-{ return o != p.operator->(); }
-
-template<class T>
-inline bool operator!= (const QPointer<T> &p, const void *o)
-{ return p.operator->() != o; }
-
-#endif
-
template <class T>
inline bool operator!=(T *o, const QPointer<T> &p)
{ return o != p.operator->(); }
@@ -174,17 +131,6 @@ template<class T>
inline bool operator!= (const QPointer<T> &p1, const QPointer<T> &p2)
{ return p1.operator->() != p2.operator->() ; }
-// Make MSVC < 1400 (2005) handle "if (NULL == p)" syntax
-#if defined(Q_CC_MSVC) && (_MSC_VER < 1400)
-template<class T>
-inline bool operator== (int i, const QPointer<T> &p)
-{ Q_ASSERT(i == 0); return !i && p.isNull(); }
-
-template<class T>
-inline bool operator!= (int i, const QPointer<T> &p)
-{ Q_ASSERT(i == 0); return !i && !p.isNull(); }
-#endif
-
template<typename T>
QPointer<T>
qPointerFromVariant(const QVariant &variant)
@@ -194,8 +140,6 @@ qPointerFromVariant(const QVariant &variant)
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_QOBJECT
#endif // QPOINTER_H
diff --git a/src/corelib/kernel/qsharedmemory.h b/src/corelib/kernel/qsharedmemory.h
index d87ba02ac9..6b44548f44 100644
--- a/src/corelib/kernel/qsharedmemory.h
+++ b/src/corelib/kernel/qsharedmemory.h
@@ -44,8 +44,6 @@
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -114,7 +112,5 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSHAREDMEMORY_H
diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h
index dd9856adf5..9f1e6c8aa1 100644
--- a/src/corelib/kernel/qsharedmemory_p.h
+++ b/src/corelib/kernel/qsharedmemory_p.h
@@ -69,7 +69,7 @@ namespace QSharedMemoryPrivate
#include "qsystemsemaphore.h"
#include "private/qobject_p.h"
-#if !defined(Q_OS_WIN) && !defined(Q_OS_LINUX_ANDROID)
+#if !defined(Q_OS_WIN) && !defined(Q_OS_ANDROID)
# include <sys/sem.h>
#endif
diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp
index 7f13e3b1a2..fdd73657a9 100644
--- a/src/corelib/kernel/qsharedmemory_unix.cpp
+++ b/src/corelib/kernel/qsharedmemory_unix.cpp
@@ -151,9 +151,6 @@ key_t QSharedMemoryPrivate::handle()
*/
int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
{
- if (QFile::exists(fileName))
- return 0;
-
int fd = qt_safe_open(QFile::encodeName(fileName).constData(),
O_EXCL | O_CREAT | O_RDWR, 0640);
if (-1 == fd) {
diff --git a/src/corelib/kernel/qsignalmapper.h b/src/corelib/kernel/qsignalmapper.h
index f1f4428118..997e8e46de 100644
--- a/src/corelib/kernel/qsignalmapper.h
+++ b/src/corelib/kernel/qsignalmapper.h
@@ -44,8 +44,6 @@
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QSignalMapperPrivate;
@@ -86,6 +84,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSIGNALMAPPER_H
diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h
index 97321521e4..8cc6b9c4c4 100644
--- a/src/corelib/kernel/qsocketnotifier.h
+++ b/src/corelib/kernel/qsocketnotifier.h
@@ -44,8 +44,6 @@
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QSocketNotifierPrivate;
@@ -84,6 +82,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSOCKETNOTIFIER_H
diff --git a/src/corelib/kernel/qsystemerror_p.h b/src/corelib/kernel/qsystemerror_p.h
index 94bfb5deb4..4b46011129 100644
--- a/src/corelib/kernel/qsystemerror_p.h
+++ b/src/corelib/kernel/qsystemerror_p.h
@@ -66,14 +66,14 @@ public:
StandardLibraryError,
NativeError
};
-
+
inline QSystemError(int error, ErrorScope scope);
inline QSystemError();
-
+
QString toString();
inline ErrorScope scope();
inline int error();
-
+
//data members
int errorCode;
ErrorScope errorScope;
diff --git a/src/corelib/kernel/qsystemsemaphore.h b/src/corelib/kernel/qsystemsemaphore.h
index 52547f0c1f..b7dd220832 100644
--- a/src/corelib/kernel/qsystemsemaphore.h
+++ b/src/corelib/kernel/qsystemsemaphore.h
@@ -45,8 +45,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -96,7 +94,5 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QSYSTEMSEMAPHORE_H
diff --git a/src/corelib/kernel/qsystemsemaphore_win.cpp b/src/corelib/kernel/qsystemsemaphore_win.cpp
index 6b064c1d52..835a9fde5b 100644
--- a/src/corelib/kernel/qsystemsemaphore_win.cpp
+++ b/src/corelib/kernel/qsystemsemaphore_win.cpp
@@ -46,7 +46,7 @@
#include <qt_windows.h>
QT_BEGIN_NAMESPACE
-
+
#ifndef QT_NO_SYSTEMSEMAPHORE
QSystemSemaphorePrivate::QSystemSemaphorePrivate() :
diff --git a/src/corelib/kernel/qtimer.h b/src/corelib/kernel/qtimer.h
index 9a90ecc772..3484f4dba8 100644
--- a/src/corelib/kernel/qtimer.h
+++ b/src/corelib/kernel/qtimer.h
@@ -42,13 +42,13 @@
#ifndef QTIMER_H
#define QTIMER_H
+#include <QtCore/qglobal.h>
+
#ifndef QT_NO_QOBJECT
#include <QtCore/qbasictimer.h> // conceptual inheritance
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -114,8 +114,6 @@ inline void QTimer::setSingleShot(bool asingleShot) { single = asingleShot; }
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QT_NO_QOBJECT
#endif // QTIMER_H
diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp
index 0eee425cf9..0e33fa697a 100644
--- a/src/corelib/kernel/qtimerinfo_unix.cpp
+++ b/src/corelib/kernel/qtimerinfo_unix.cpp
@@ -77,7 +77,7 @@ QTimerInfoList::QTimerInfoList()
msPerTick = 1000/ticksPerSecond;
} else {
// detected monotonic timers
- previousTime.tv_sec = previousTime.tv_usec = 0;
+ previousTime.tv_sec = previousTime.tv_nsec = 0;
previousTicks = 0;
ticksPerSecond = 0;
msPerTick = 0;
@@ -87,25 +87,24 @@ QTimerInfoList::QTimerInfoList()
firstTimerInfo = 0;
}
-timeval QTimerInfoList::updateCurrentTime()
+timespec QTimerInfoList::updateCurrentTime()
{
return (currentTime = qt_gettime());
}
#if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC) && !defined(Q_OS_INTEGRITY)) || defined(QT_BOOTSTRAPPED)
-template <>
-timeval qAbs(const timeval &t)
+timespec qAbsTimespec(const timespec &t)
{
- timeval tmp = t;
+ timespec tmp = t;
if (tmp.tv_sec < 0) {
tmp.tv_sec = -tmp.tv_sec - 1;
- tmp.tv_usec -= 1000000;
+ tmp.tv_nsec -= 1000000000;
}
- if (tmp.tv_sec == 0 && tmp.tv_usec < 0) {
- tmp.tv_usec = -tmp.tv_usec;
+ if (tmp.tv_sec == 0 && tmp.tv_nsec < 0) {
+ tmp.tv_nsec = -tmp.tv_nsec;
}
- return normalizedTimeval(tmp);
+ return normalizedTimespec(tmp);
}
/*
@@ -115,7 +114,7 @@ timeval qAbs(const timeval &t)
If /a delta is nonzero, delta is set to our best guess at how much the system clock was changed.
*/
-bool QTimerInfoList::timeChanged(timeval *delta)
+bool QTimerInfoList::timeChanged(timespec *delta)
{
#ifdef Q_OS_NACL
Q_UNUSED(delta)
@@ -125,13 +124,13 @@ bool QTimerInfoList::timeChanged(timeval *delta)
clock_t currentTicks = times(&unused);
clock_t elapsedTicks = currentTicks - previousTicks;
- timeval elapsedTime = currentTime - previousTime;
+ timespec elapsedTime = currentTime - previousTime;
- timeval elapsedTimeTicks;
+ timespec elapsedTimeTicks;
elapsedTimeTicks.tv_sec = elapsedTicks / ticksPerSecond;
- elapsedTimeTicks.tv_usec = (((elapsedTicks * 1000) / ticksPerSecond) % 1000) * 1000;
+ elapsedTimeTicks.tv_nsec = (((elapsedTicks * 1000) / ticksPerSecond) % 1000) * 1000 * 1000;
- timeval dummy;
+ timespec dummy;
if (!delta)
delta = &dummy;
*delta = elapsedTime - elapsedTimeTicks;
@@ -141,16 +140,16 @@ bool QTimerInfoList::timeChanged(timeval *delta)
// If tick drift is more than 10% off compared to realtime, we assume that the clock has
// been set. Of course, we have to allow for the tick granularity as well.
- timeval tickGranularity;
+ timespec tickGranularity;
tickGranularity.tv_sec = 0;
- tickGranularity.tv_usec = msPerTick * 1000;
- return elapsedTimeTicks < ((qAbs(*delta) - tickGranularity) * 10);
+ tickGranularity.tv_nsec = msPerTick * 1000 * 1000;
+ return elapsedTimeTicks < ((qAbsTimespec(*delta) - tickGranularity) * 10);
}
/*
repair broken timer
*/
-void QTimerInfoList::timerRepair(const timeval &diff)
+void QTimerInfoList::timerRepair(const timespec &diff)
{
// repair all timers
for (int i = 0; i < size(); ++i) {
@@ -163,7 +162,7 @@ void QTimerInfoList::repairTimersIfNeeded()
{
if (QElapsedTimer::isMonotonic())
return;
- timeval delta;
+ timespec delta;
if (timeChanged(&delta))
timerRepair(delta);
}
@@ -190,27 +189,27 @@ void QTimerInfoList::timerInsert(QTimerInfo *ti)
insert(index+1, ti);
}
-inline timeval &operator+=(timeval &t1, int ms)
+inline timespec &operator+=(timespec &t1, int ms)
{
t1.tv_sec += ms / 1000;
- t1.tv_usec += ms % 1000 * 1000;
- return normalizedTimeval(t1);
+ t1.tv_nsec += ms % 1000 * 1000 * 1000;
+ return normalizedTimespec(t1);
}
-inline timeval operator+(const timeval &t1, int ms)
+inline timespec operator+(const timespec &t1, int ms)
{
- timeval t2 = t1;
+ timespec t2 = t1;
return t2 += ms;
}
-static timeval roundToMillisecond(timeval val)
+static timespec roundToMillisecond(timespec val)
{
// always round up
// worst case scenario is that the first trigger of a 1-ms timer is 0.999 ms late
- int us = val.tv_usec % 1000;
- val.tv_usec += 1000 - us;
- return normalizedTimeval(val);
+ int ns = val.tv_nsec % (1000 * 1000);
+ val.tv_nsec += 1000 * 1000 - ns;
+ return normalizedTimespec(val);
}
#ifdef QTIMERINFO_DEBUG
@@ -227,7 +226,7 @@ QDebug operator<<(QDebug s, Qt::TimerType t)
}
#endif
-static void calculateCoarseTimerTimeout(QTimerInfo *t, timeval currentTime)
+static void calculateCoarseTimerTimeout(QTimerInfo *t, timespec currentTime)
{
// The coarse timer works like this:
// - interval under 40 ms: round to even
@@ -246,7 +245,7 @@ static void calculateCoarseTimerTimeout(QTimerInfo *t, timeval currentTime)
// The objective is to make most timers wake up at the same time, thereby reducing CPU wakeups.
register uint interval = uint(t->interval);
- register uint msec = uint(t->timeout.tv_usec) / 1000;
+ register uint msec = uint(t->timeout.tv_nsec) / 1000 / 1000;
Q_ASSERT(interval >= 20);
// Calculate how much we can round and still keep within 5% error
@@ -328,16 +327,16 @@ static void calculateCoarseTimerTimeout(QTimerInfo *t, timeval currentTime)
recalculate:
if (msec == 1000u) {
++t->timeout.tv_sec;
- t->timeout.tv_usec = 0;
+ t->timeout.tv_nsec = 0;
} else {
- t->timeout.tv_usec = msec * 1000;
+ t->timeout.tv_nsec = msec * 1000 * 1000;
}
if (t->timeout < currentTime)
t->timeout += interval;
}
-static void calculateNextTimeout(QTimerInfo *t, timeval currentTime)
+static void calculateNextTimeout(QTimerInfo *t, timespec currentTime)
{
switch (t->timerType) {
case Qt::PreciseTimer:
@@ -383,9 +382,9 @@ static void calculateNextTimeout(QTimerInfo *t, timeval currentTime)
Returns the time to wait for the next timer, or null if no timers
are waiting.
*/
-bool QTimerInfoList::timerWait(timeval &tm)
+bool QTimerInfoList::timerWait(timespec &tm)
{
- timeval currentTime = updateCurrentTime();
+ timespec currentTime = updateCurrentTime();
repairTimersIfNeeded();
// Find first waiting timer not already active
@@ -406,7 +405,7 @@ bool QTimerInfoList::timerWait(timeval &tm)
} else {
// no time to wait
tm.tv_sec = 0;
- tm.tv_usec = 0;
+ tm.tv_nsec = 0;
}
return true;
@@ -419,9 +418,9 @@ bool QTimerInfoList::timerWait(timeval &tm)
*/
int QTimerInfoList::timerRemainingTime(int timerId)
{
- timeval currentTime = updateCurrentTime();
+ timespec currentTime = updateCurrentTime();
repairTimersIfNeeded();
- timeval tm = {0, 0};
+ timespec tm = {0, 0};
for (int i = 0; i < count(); ++i) {
register QTimerInfo *t = at(i);
@@ -429,7 +428,7 @@ int QTimerInfoList::timerRemainingTime(int timerId)
if (currentTime < t->timeout) {
// time to wait
tm = roundToMillisecond(t->timeout - currentTime);
- return tm.tv_sec*1000 + tm.tv_usec/1000;
+ return tm.tv_sec*1000 + tm.tv_nsec/1000/1000;
} else {
return 0;
}
@@ -452,7 +451,7 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time
t->obj = object;
t->activateRef = 0;
- timeval expected = updateCurrentTime() + interval;
+ timespec expected = updateCurrentTime() + interval;
switch (timerType) {
case Qt::PreciseTimer:
@@ -487,10 +486,10 @@ void QTimerInfoList::registerTimer(int timerId, int interval, Qt::TimerType time
t->interval += 1;
t->interval >>= 1;
t->timeout.tv_sec = currentTime.tv_sec + t->interval;
- t->timeout.tv_usec = 0;
+ t->timeout.tv_nsec = 0;
// if we're past the half-second mark, increase the timeout again
- if (currentTime.tv_usec > 500*1000)
+ if (currentTime.tv_nsec > 500*1000*1000)
++t->timeout.tv_sec;
}
@@ -574,7 +573,7 @@ int QTimerInfoList::activateTimers()
int n_act = 0, maxCount = 0;
firstTimerInfo = 0;
- timeval currentTime = updateCurrentTime();
+ timespec currentTime = updateCurrentTime();
// qDebug() << "Thread" << QThread::currentThreadId() << "woken up at" << currentTime;
repairTimersIfNeeded();
diff --git a/src/corelib/kernel/qtimerinfo_unix_p.h b/src/corelib/kernel/qtimerinfo_unix_p.h
index 549062bd1f..ec7560429b 100644
--- a/src/corelib/kernel/qtimerinfo_unix_p.h
+++ b/src/corelib/kernel/qtimerinfo_unix_p.h
@@ -66,7 +66,7 @@ struct QTimerInfo {
int id; // - timer identifier
int interval; // - timer interval in milliseconds
Qt::TimerType timerType; // - timer type
- timeval timeout; // - when to actually fire
+ timespec timeout; // - when to actually fire
QObject *obj; // - object to receive event
QTimerInfo **activateRef; // - ref from activateTimers
@@ -80,13 +80,13 @@ struct QTimerInfo {
class Q_CORE_EXPORT QTimerInfoList : public QList<QTimerInfo*>
{
#if ((_POSIX_MONOTONIC_CLOCK-0 <= 0) && !defined(Q_OS_MAC)) || defined(QT_BOOTSTRAPPED)
- timeval previousTime;
+ timespec previousTime;
clock_t previousTicks;
int ticksPerSecond;
int msPerTick;
- bool timeChanged(timeval *delta);
- void timerRepair(const timeval &);
+ bool timeChanged(timespec *delta);
+ void timerRepair(const timespec &);
#endif
// state variables used by activateTimers()
@@ -95,13 +95,13 @@ class Q_CORE_EXPORT QTimerInfoList : public QList<QTimerInfo*>
public:
QTimerInfoList();
- timeval currentTime;
- timeval updateCurrentTime();
+ timespec currentTime;
+ timespec updateCurrentTime();
// must call updateCurrentTime() first!
void repairTimersIfNeeded();
- bool timerWait(timeval &);
+ bool timerWait(timespec &);
void timerInsert(QTimerInfo *);
int timerRemainingTime(int timerId);
diff --git a/src/corelib/kernel/qtranslator.h b/src/corelib/kernel/qtranslator.h
index 98c0b81c97..c3957aff3f 100644
--- a/src/corelib/kernel/qtranslator.h
+++ b/src/corelib/kernel/qtranslator.h
@@ -45,8 +45,6 @@
#include <QtCore/qobject.h>
#include <QtCore/qbytearray.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -87,6 +85,4 @@ private:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QTRANSLATOR_H
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index ad7ce708ad..c1bb460e7b 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1529,10 +1529,13 @@ QVariant::QVariant(const QLocale &l)
QVariant::QVariant(const QRegExp &regExp)
: d(RegExp)
{ v_construct<QRegExp>(&d, regExp); }
+#endif // QT_NO_REGEXP
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGULAREXPRESSION
QVariant::QVariant(const QRegularExpression &re)
: d(RegularExpression)
{ v_construct<QRegularExpression>(&d, re); }
+#endif
QVariant::QVariant(const QUuid &uuid)
: d(Uuid)
{ v_construct<QUuid>(&d, uuid); }
@@ -1552,7 +1555,6 @@ QVariant::QVariant(const QJsonDocument &jsonDocument)
: d(QMetaType::QJsonDocument)
{ v_construct<QJsonDocument>(&d, jsonDocument); }
#endif // QT_BOOTSTRAPPED
-#endif // QT_NO_REGEXP
/*!
Returns the storage type of the value stored in the variant.
@@ -2222,6 +2224,7 @@ QRegExp QVariant::toRegExp() const
}
#endif
+#ifndef QT_BOOTSTRAPPED
/*!
\fn QRegularExpression QVariant::toRegularExpression() const
\since 5.0
@@ -2231,13 +2234,12 @@ QRegExp QVariant::toRegExp() const
\sa canConvert(), convert()
*/
-#ifndef QT_BOOTSTRAPPED
-#ifndef QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
QRegularExpression QVariant::toRegularExpression() const
{
return qVariantToHelper<QRegularExpression>(d, handlerManager);
}
-#endif
+#endif // QT_NO_REGULAREXPRESSION
/*!
\since 5.0
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index d21f48f98c..6f212f5000 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -51,8 +51,6 @@
#include <QtCore/qstring.h>
#include <QtCore/qobject.h>
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
@@ -76,8 +74,10 @@ class QRect;
class QRectF;
#ifndef QT_NO_REGEXP
class QRegExp;
-class QRegularExpression;
#endif // QT_NO_REGEXP
+#ifndef QT_NO_REGULAREXPRESSION
+class QRegularExpression;
+#endif // QT_NO_REGULAREXPRESSION
class QTextFormat;
class QTextLength;
class QUrl;
@@ -240,11 +240,11 @@ class Q_CORE_EXPORT QVariant
QVariant(const QLocale &locale);
#ifndef QT_NO_REGEXP
QVariant(const QRegExp &regExp);
-#ifndef QT_BOOTSRAPPED
- QVariant(const QRegularExpression &re);
-#endif // QT_BOOTSTRAPPED
#endif // QT_NO_REGEXP
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGULAREXPRESSION
+ QVariant(const QRegularExpression &re);
+#endif // QT_NO_REGULAREXPRESSION
QVariant(const QUrl &url);
QVariant(const QEasingCurve &easing);
QVariant(const QUuid &uuid);
@@ -253,7 +253,7 @@ class Q_CORE_EXPORT QVariant
QVariant(const QJsonObject &jsonObject);
QVariant(const QJsonArray &jsonArray);
QVariant(const QJsonDocument &jsonDocument);
-#endif
+#endif // QT_BOOTSTRAPPED
QVariant& operator=(const QVariant &other);
#ifdef Q_COMPILER_RVALUE_REFS
@@ -313,11 +313,11 @@ class Q_CORE_EXPORT QVariant
QLocale toLocale() const;
#ifndef QT_NO_REGEXP
QRegExp toRegExp() const;
-#ifndef QT_BOOTSTRAPPED
- QRegularExpression toRegularExpression() const;
-#endif // QT_BOOTSTRAPPED
#endif // QT_NO_REGEXP
#ifndef QT_BOOTSTRAPPED
+#ifndef QT_NO_REGULAREXPRESSION
+ QRegularExpression toRegularExpression() const;
+#endif // QT_NO_REGULAREXPRESSION
QUrl toUrl() const;
QEasingCurve toEasingCurve() const;
QUuid toUuid() const;
@@ -326,7 +326,7 @@ class Q_CORE_EXPORT QVariant
QJsonObject toJsonObject() const;
QJsonArray toJsonArray() const;
QJsonDocument toJsonDocument() const;
-#endif
+#endif // QT_BOOTSTRAPPED
#ifndef QT_NO_DATASTREAM
void load(QDataStream &ds);
@@ -484,7 +484,7 @@ public:
template <typename T>
inline QVariant qVariantFromValue(const T &t)
{
- return QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t, QTypeInfo<T>::isPointer);
+ return QVariant(qMetaTypeId<T>(), &t, QTypeInfo<T>::isPointer);
}
template <>
@@ -494,7 +494,7 @@ template <typename T>
inline void qVariantSetValue(QVariant &v, const T &t)
{
//if possible we reuse the current QVariant private
- const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0));
+ const uint type = qMetaTypeId<T>();
QVariant::Private &d = v.data_ptr();
if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) {
d.type = type;
@@ -568,7 +568,7 @@ namespace QtPrivate {
{
static T metaType(const QVariant &v)
{
- const int vid = qMetaTypeId<T>(static_cast<T *>(0));
+ const int vid = qMetaTypeId<T>();
if (vid == v.userType())
return *reinterpret_cast<const T *>(v.constData());
if (vid < int(QMetaType::User)) {
@@ -620,6 +620,4 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant::Type);
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QVARIANT_H
diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h
index e7940e0039..04b9d92f55 100644
--- a/src/corelib/kernel/qvariant_p.h
+++ b/src/corelib/kernel/qvariant_p.h
@@ -150,7 +150,7 @@ inline void v_construct(QVariant::Private *x, const T &t)
template <class T>
inline void v_clear(QVariant::Private *d, T* = 0)
{
-
+
if (!QVariantIntegrator<T>::CanUseInternalSpace) {
//now we need to cast
//because QVariant::PrivateShared doesn't have a virtual destructor
diff --git a/src/corelib/kernel/qwineventnotifier.h b/src/corelib/kernel/qwineventnotifier.h
index ca84054d71..56605d9aaa 100644
--- a/src/corelib/kernel/qwineventnotifier.h
+++ b/src/corelib/kernel/qwineventnotifier.h
@@ -47,8 +47,6 @@
#ifdef Q_OS_WIN
#include "QtCore/qt_windows.h"
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QWinEventNotifierPrivate;
@@ -83,8 +81,6 @@ protected:
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // Q_OS_WIN
#endif // QWINEVENTNOTIFIER_H