From d32f47b70387713335656a8e93f289c819fb9b05 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 3 Jun 2015 17:04:53 +0200 Subject: fix usage of wince scope Fix style issues along the way. Change-Id: Ic6a6de28e198eb0b14c198b802e78845703909b9 Reviewed-by: Joerg Bornemann --- src/corelib/kernel/kernel.pri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index dabbb2dbbe..65dc44def2 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -84,7 +84,7 @@ win32 { } } -wince*: { +wince { SOURCES += \ kernel/qfunctions_wince.cpp HEADERS += \ -- cgit v1.2.3 From 36640aa0afb722479ba47d6fbd9401c433dead41 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 3 Jun 2015 15:28:01 +0200 Subject: Don't enforce all QMetaType::TypeFlag difference across Qt versions QMetaType::IsGadget was introduced in Qt 5.5 and set when Q_GADGET is used. If an existing Qt 5.4 class was converted to a gadget in Qt 5.5+, the two types would have differing QMetaType::TypeFlags. Such a conversion happened for QGeoCoordinate, QGeoShape, QGeoRectangle and QGeoCircle. There might be other classes too. In principle, the same problem exists for every future addition to QMetaType::TypeFlag too. This patch ensures that new flags are kept in the metatype database and the related qFatal call is not triggered for any flag >= TypeFlag::WasDeclaredAsMetaType. Change-Id: Ibb15daeb28d9a11b7f31658f4219cbca2499213f Task-number: QTBUG-46454 Reviewed-by: Alex Blasche Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qmetatype.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 3b70ef92ed..0f9cf41b77 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1046,6 +1046,16 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, if (idx >= User) { previousSize = ct->at(idx - User).size; previousFlags = ct->at(idx - User).flags; + + // Set new/additional flags in case of old library/app. + // Ensures that older code works in conjunction with new Qt releases + // requiring the new flags. + if (flags != previousFlags) { + QCustomTypeInfo &inf = ct->data()[idx - User]; + inf.flags |= flags; + if (metaObject) + inf.metaObject = metaObject; + } } } @@ -1061,11 +1071,11 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, normalizedTypeName.constData(), idx, previousSize, size); } + // Do not compare types higher than 0x100: // Ignore WasDeclaredAsMetaType inconsitency, to many users were hitting the problem - previousFlags |= WasDeclaredAsMetaType; - flags |= WasDeclaredAsMetaType; - - if (previousFlags != flags) { + // Ignore IsGadget as it was added in Qt 5.5 + // Ignore all the future flags as well + if ((previousFlags ^ flags) & 0xff) { const int maskForTypeInfo = NeedsConstruction | NeedsDestruction | MovableType; const char *msg = "QMetaType::registerType: Binary compatibility break. " "\nType flags for type '%s' [%i] don't match. Previously " -- cgit v1.2.3 From 05dcc0499bfae43b8ae4100ab71902a13dd40f74 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 11 Jun 2015 10:23:52 +0200 Subject: QCoreApplication::applicationFilePath(): Fix array bounds violation of argv. Check for argc > 0 before accessing argv[0]. tst_qapplication constructs QApplication(0, 0) and has been observed to crash sporadically. Fix valgrind error: =9845== Conditional jump or move depends on uninitialised value(s) ==9845== at 0x4C2F1BC: strcmp (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==9845== by 0x5DEEFB3: qstrcmp(char const*, char const*) (qbytearray.cpp:262) ==9845== by 0x6011EAA: QCoreApplication::applicationFilePath() (qcoreapplication.cpp:2058) ==9845== by 0x6011D0B: QCoreApplication::applicationDirPath() (qcoreapplication.cpp:2029) ==9845== by 0x5DD285D: QLibraryInfoPrivate::findConfiguration() (qlibraryinfo.cpp:184) ==9845== by 0x5DD32AF: QLibraryInfo::platformPluginArguments(QString const&) (qlibraryinfo.cpp:596) ==9845== by 0x5746A95: init_platform(QString const&, QString const&, QString const&, int&, char**) (qguiapplication.cpp:1017) ==9845== by 0x5747C91: QGuiApplicationPrivate::createPlatformIntegration() (qguiapplication.cpp:1177) ==9845== by 0x5747DDE: QGuiApplicationPrivate::createEventDispatcher() (qguiapplication.cpp:1194) ==9845== by 0x4FAF81D: QApplicationPrivate::createEventDispatcher() (qapplication.cpp:196) ==9845== by 0x600F568: QCoreApplication::init() (qcoreapplication.cpp:768) ==9845== by 0x600F2C4: QCoreApplication::QCoreApplication(QCoreApplicationPrivate&) (qcoreapplication.cpp:689) ==9845== by 0x574594C: QGuiApplication::QGuiApplication(QGuiApplicationPrivate&) (qguiapplication.cpp:570) ==9845== by 0x4FB008A: QApplication::QApplication(int&, char**, int) (qapplication.cpp:569) ==9845== by 0x41148A: tst_QApplication::lastWindowClosed() (tst_qapplication.cpp:561) Change-Id: I2fb324ab63617f14f5f43835154aae339bfa9520 Reviewed-by: Simon Hausmann --- src/corelib/kernel/qcoreapplication.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index b6f839d554..34dad73c80 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2054,11 +2054,13 @@ QString QCoreApplication::applicationFilePath() QCoreApplicationPrivate *d = self->d_func(); - static char *procName = d->argv[0]; - if (qstrcmp(procName, d->argv[0]) != 0) { - // clear the cache if the procname changes, so we reprocess it. - QCoreApplicationPrivate::clearApplicationFilePath(); - procName = d->argv[0]; + if (d->argc) { + static const char *procName = d->argv[0]; + if (qstrcmp(procName, d->argv[0]) != 0) { + // clear the cache if the procname changes, so we reprocess it. + QCoreApplicationPrivate::clearApplicationFilePath(); + procName = d->argv[0]; + } } if (QCoreApplicationPrivate::cachedApplicationFilePath) -- cgit v1.2.3 From b2be272d354defaebd82dfaa2dffefa5a8f3a303 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 19 May 2015 11:49:37 -0700 Subject: Make QMetaObject::Connection check its state deeply Since Connection can be copied, one copy could be used for disconnecting, but the other's d_ptr wouldn't get updated and would continue to report as still connected. This patch fixes that by making it check the internal state. That is only done after d_ptr is already known to be non-null. Unfortunately, that is the common path: if (connect(sender, &Sender::signal, [] {})) will call an out-of-line function. I don't see a way out. Task-number: QTBUG-46213 Change-Id: I66a35ce5f88941f29aa6ffff13dfb45dca68a350 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qobject.cpp | 10 ++++++++++ src/corelib/kernel/qobjectdefs.h | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 1836405b9c..676a529dfe 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -4913,6 +4913,16 @@ QMetaObject::Connection::~Connection() static_cast(d_ptr)->deref(); } +/*! \internal Returns true if the object is still connected */ +bool QMetaObject::Connection::isConnected_helper() const +{ + Q_ASSERT(d_ptr); // we're only called from operator RestrictedBool() const + QObjectPrivate::Connection *c = static_cast(d_ptr); + + return c->receiver; +} + + /*! \fn QMetaObject::Connection::operator bool() const diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 4d01264906..6484507a12 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -472,6 +472,7 @@ class Q_CORE_EXPORT QMetaObject::Connection { friend class QObject; friend class QObjectPrivate; friend struct QMetaObject; + bool isConnected_helper() const; public: ~Connection(); Connection(); @@ -481,7 +482,7 @@ public: operator bool() const; #else typedef void *Connection::*RestrictedBool; - operator RestrictedBool() const { return d_ptr ? &Connection::d_ptr : 0; } + operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : 0; } #endif #ifdef Q_COMPILER_RVALUE_REFS -- cgit v1.2.3 From 4fe865ac7a701b7c950ee0c79b6153b43e1b49ae Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 16 Apr 2015 17:32:18 -0700 Subject: Doc: document future direction of QCoreApplication::notify() It will definitely not be called for events outside the main thread, but we haven't decided for the main thread, in Qt 6. [ChangeLog][Future direction notices] In Qt 6, QCoreApplication::notify() will not be called for events being delivered to objects outside the main thread. The reason for that is that the main application object may begin destruction while those threads are still delivering events, which is undefined behavior. Applications that currently override notify() and use that function outside the main thread are advised to find other solutions in the mean time. Change-Id: I27eaacb532114dd188c4ffff13d5a5c8df3bc85b Reviewed-by: Simon Hausmann --- src/corelib/kernel/qcoreapplication.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index b6f839d554..ecafe91b43 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1005,6 +1005,17 @@ bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event) do not change the focus widget. \endlist + \b{Future direction:} This function will not be called for objects that live + outside the main thread in Qt 6. Applications that need that functionality + should find other solutions for their event inspection needs in the meantime. + The change may be extended to the main thread, causing this function to be + deprecated. + + \warning If you override this function, you must ensure all threads that + process events stop doing so before your application object begins + destruction. This includes threads started by other libraries that you may be + using, but does not apply to Qt's own threads. + \sa QObject::event(), installNativeEventFilter() */ -- cgit v1.2.3 From bf24838c3344f009f9fe40f596a4eab798f071b3 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 10 Jun 2015 12:48:17 +0200 Subject: Use qthread_win.cpp for WinRT as well Since of Windows (Phone) 8.1 most of the desktop's thread functionality is also available, so we might be able to share the code and get rid of the extra implementation for WinRT. Task-number: QTBUG-43837 Change-Id: I0ce907cd94899834527f88c70e1e395bafdb14b3 Reviewed-by: Maurice Kalinowski --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index 1509996199..0274f35dba 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -144,7 +144,10 @@ private: IID_PPV_ARGS(&application)); RETURN_VOID_IF_FAILED("Failed to get the application factory"); - ComPtr view; + static ComPtr view; + if (view) + return; + hr = application->get_MainView(&view); RETURN_VOID_IF_FAILED("Failed to get the main view"); @@ -166,13 +169,6 @@ QEventDispatcherWinRT::QEventDispatcherWinRT(QObject *parent) { Q_D(QEventDispatcherWinRT); - // Special treatment for the WinMain thread, as it is created before the UI - static bool firstThread = true; - if (firstThread) { - firstThread = false; - return; - } - d->fetchCoreDispatcher(); } @@ -212,6 +208,7 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags) DWORD waitResult = WaitForMultipleObjectsEx(timerHandles.count(), timerHandles.constData(), FALSE, 1, TRUE); if (waitResult >= WAIT_OBJECT_0 && waitResult < WAIT_OBJECT_0 + timerHandles.count()) { const HANDLE handle = timerHandles.value(waitResult - WAIT_OBJECT_0); + ResetEvent(handle); const int timerId = d->timerHandleToId.value(handle); if (timerId == INTERRUPT_HANDLE) break; @@ -288,8 +285,8 @@ void QEventDispatcherWinRT::registerTimer(int timerId, int interval, Qt::TimerTy TimeSpan period; period.Duration = interval ? (interval * 10000) : 1; // TimeSpan is based on 100-nanosecond units IThreadPoolTimer *timer; - const HANDLE handle = CreateEventEx(NULL, NULL, NULL, SYNCHRONIZE|EVENT_MODIFY_STATE); - const HANDLE cancelHandle = CreateEventEx(NULL, NULL, NULL, SYNCHRONIZE|EVENT_MODIFY_STATE); + const HANDLE handle = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, SYNCHRONIZE | EVENT_MODIFY_STATE); + const HANDLE cancelHandle = CreateEventEx(NULL, NULL, CREATE_EVENT_MANUAL_RESET, SYNCHRONIZE|EVENT_MODIFY_STATE); HRESULT hr = d->timerFactory->CreatePeriodicTimerWithCompletion( Callback([handle, cancelHandle](IThreadPoolTimer *timer) { DWORD cancelResult = WaitForSingleObjectEx(cancelHandle, 0, TRUE); @@ -486,7 +483,9 @@ bool QEventDispatcherWinRT::event(QEvent *e) QEventDispatcherWinRTPrivate::QEventDispatcherWinRTPrivate() { - CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + const bool isGuiThread = QCoreApplication::instance() && + QThread::currentThread() == QCoreApplication::instance()->thread(); + CoInitializeEx(NULL, isGuiThread ? COINIT_APARTMENTTHREADED : COINIT_MULTITHREADED); HRESULT hr; hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Threading_ThreadPoolTimer).Get(), &timerFactory); Q_ASSERT_SUCCEEDED(hr); -- cgit v1.2.3 From 756d451a15e5754ced815853598f2dec3be60aec Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 9 Jun 2015 16:03:50 +0200 Subject: winrt: don't return invalidated timers in QEventDispatcherWinRT::registeredTimers Change-Id: I0dbad7a78080cd8c18893fea8294cf540a5e9e5e Reviewed-by: Maurice Kalinowski --- src/corelib/kernel/qeventdispatcher_winrt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp index 0274f35dba..eceba8d002 100644 --- a/src/corelib/kernel/qeventdispatcher_winrt.cpp +++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp @@ -373,7 +373,7 @@ QList QEventDispatcherWinRT::registeredTime Q_D(const QEventDispatcherWinRT); QList timerInfos; foreach (const WinRTTimerInfo &info, d->timerInfos) { - if (info.object == object) + if (info.object == object && info.timerId != INVALID_TIMER_ID) timerInfos.append(info); } return timerInfos; -- cgit v1.2.3 From f64736188f3c0d35086d77c9cc6ae8a855833580 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 8 Jun 2015 18:30:21 -0400 Subject: Don't document the IsGadget flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's still some discussion as to whether it's safe to use. Until we're completely sure, don't let users use it. We can always bring it back later. Change-Id: I049a653beeb5454c9539ffff13e5e3e343da0e7d Reviewed-by: Jędrzej Nowacki --- src/corelib/kernel/qmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 0f9cf41b77..58912e3fb7 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -303,7 +303,7 @@ struct DefinedTypesFilter { \omitvalue WeakPointerToQObject \omitvalue TrackingPointerToQObject \omitvalue WasDeclaredAsMetaType - \value IsGadget This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5. + \omitvalue IsGadget This type is a Q_GADGET and it's corresponding QMetaObject can be accessed with QMetaType::metaObject Since 5.5. */ /*! -- cgit v1.2.3