From 50b9d8a931e859c027726a74ea0616e7b292e782 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 18 Oct 2016 19:12:55 +0200 Subject: Windows: Fix regression in QFSFileEnginePrivate::nativeWrite() Change 0696566b1e19c8178e00c0d14f185935e17d9e8b caused the block size to be incorrect for data > 32MB. Since bytesToWrite changes within the do...while loop, then the block size can potentially change too each time. So it needs to be recalculated each time rather than just once. Task-number: QTBUG-56616 Change-Id: I9880d0985f2d0242c30e67230be7271eb806db95 Reviewed-by: Oliver Wolff Reviewed-by: Friedemann Kleint (cherry picked from commit 683c9bc4a8e656b2251871b9d8c9952e58681a52) --- src/corelib/io/qfsfileengine_win.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index af026b8976..3251c481dd 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -433,11 +433,11 @@ qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len) // Writing on Windows fails with ERROR_NO_SYSTEM_RESOURCES when // the chunks are too large, so we limit the block size to 32MB. - const DWORD blockSize = DWORD(qMin(bytesToWrite, qint64(32 * 1024 * 1024))); qint64 totalWritten = 0; do { + const DWORD currentBlockSize = DWORD(qMin(bytesToWrite, qint64(32 * 1024 * 1024))); DWORD bytesWritten; - if (!WriteFile(fileHandle, data + totalWritten, blockSize, &bytesWritten, NULL)) { + if (!WriteFile(fileHandle, data + totalWritten, currentBlockSize, &bytesWritten, NULL)) { if (totalWritten == 0) { // Note: Only return error if the first WriteFile failed. q->setError(QFile::WriteError, qt_error_string()); -- cgit v1.2.3 From ab0ba668642d2d4c941f57e949118327530234af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 3 Oct 2016 18:41:30 +0200 Subject: Apple OS: Handle QSetting strings with embedded zero-bytes Saving strings with embedded zero-bytes (\0) as CFStrings would sometimes fail, and only write the part of the string leading up to the first zero-byte, instead of all the way to the final zero-terminator. This bug was revealed by the code-path that falls back to storing e.g. QTime as strings, via the helper method QSettingsPrivate::variantToString(). We now use the same approach as on platforms such as Windows and WinRT, where the string produced by variantToString() is checked for null-bytes, and if so, stored using a binary representation instead of as a string. For our case that means we fall back to CFData when detecting the null-byte. To separate strings from regular byte arrays, new logic has been added to variantToString() that wraps the null-byte strings in @String(). That way we can implement a fast-path when converting back from CFData, that doesn't go via the slow and lossy conversion via UTF8, and the resulting QVariant will be of type QVariant::ByteArray. The reason for using UTF-8 as the binary representation of the string is that in the case of storing a QByteArray("@foo") we need to still be able to convert it back to the same byte array, which doesn't work if the on-disk format is UTF-16. Task-number: QTBUG-56124 Change-Id: Iab2f71cf96cf3225de48dc5e71870d74b6dde1e8 Cherry-picked: 764f5bf48cc87f4c72550b853ab93b815454cd48 Reviewed-by: Thiago Macieira Reviewed-by: Jani Heikkinen --- src/corelib/io/qsettings.cpp | 6 +++++- src/corelib/io/qsettings_mac.cpp | 20 ++++++++++++++++++-- src/corelib/io/qsettings_win.cpp | 13 ++----------- src/corelib/io/qsettings_winrt.cpp | 4 ++-- 4 files changed, 27 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 8bdd148e28..05f6c22fc2 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -417,7 +417,9 @@ QString QSettingsPrivate::variantToString(const QVariant &v) case QVariant::Double: case QVariant::KeySequence: { result = v.toString(); - if (result.startsWith(QLatin1Char('@'))) + if (result.contains(QChar::Null)) + result = QLatin1String("@String(") + result + QLatin1Char(')'); + else if (result.startsWith(QLatin1Char('@'))) result.prepend(QLatin1Char('@')); break; } @@ -477,6 +479,8 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s) if (s.endsWith(QLatin1Char(')'))) { if (s.startsWith(QLatin1String("@ByteArray("))) { return QVariant(s.midRef(11, s.size() - 12).toLatin1()); + } else if (s.startsWith(QLatin1String("@String("))) { + return QVariant(s.midRef(8, s.size() - 9).toString()); } else if (s.startsWith(QLatin1String("@Variant(")) || s.startsWith(QLatin1String("@DateTime("))) { #ifndef QT_NO_DATASTREAM diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index d73cc4d298..4282fcbe2c 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -214,7 +214,14 @@ static QCFType macValue(const QVariant &value) case QVariant::String: string_case: default: - result = QCFString::toCFStringRef(QSettingsPrivate::variantToString(value)); + QString string = QSettingsPrivate::variantToString(value); + if (string.contains(QChar::Null)) { + QByteArray ba = string.toUtf8(); + result = CFDataCreate(kCFAllocatorDefault, reinterpret_cast(ba.data()), + CFIndex(ba.size())); + } else { + result = QCFString::toCFStringRef(string); + } } return result; } @@ -267,8 +274,17 @@ static QVariant qtValue(CFPropertyListRef cfvalue) return (bool)CFBooleanGetValue(static_cast(cfvalue)); } else if (typeId == CFDataGetTypeID()) { CFDataRef cfdata = static_cast(cfvalue); - return QByteArray(reinterpret_cast(CFDataGetBytePtr(cfdata)), + QByteArray byteArray = QByteArray(reinterpret_cast(CFDataGetBytePtr(cfdata)), CFDataGetLength(cfdata)); + + // Fast-path for QByteArray, so that we don't have to go + // though the expensive and lossy conversion via UTF-8. + if (!byteArray.startsWith('@')) + return byteArray; + + const QString str = QString::fromUtf8(byteArray.constData(), byteArray.size()); + return QSettingsPrivate::stringToVariant(str); + } else if (typeId == CFDictionaryGetTypeID()) { CFDictionaryRef cfdict = static_cast(cfvalue); CFTypeID arrayTypeId = CFArrayGetTypeID(); diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 05ed51e999..53e1ed360b 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -675,15 +675,6 @@ void QWinSettingsPrivate::remove(const QString &uKey) } } -static bool stringContainsNullChar(const QString &s) -{ - for (int i = 0; i < s.length(); ++i) { - if (s.at(i).unicode() == 0) - return true; - } - return false; -} - void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) { if (writeHandle() == 0) { @@ -712,7 +703,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) QStringList l = variantListToStringList(value.toList()); QStringList::const_iterator it = l.constBegin(); for (; it != l.constEnd(); ++it) { - if ((*it).length() == 0 || stringContainsNullChar(*it)) { + if ((*it).length() == 0 || it->contains(QChar::Null)) { type = REG_BINARY; break; } @@ -756,7 +747,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) // If the string does not contain '\0', we can use REG_SZ, the native registry // string type. Otherwise we use REG_BINARY. QString s = variantToString(value); - type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ; + type = s.contains(QChar::Null) ? REG_BINARY : REG_SZ; if (type == REG_BINARY) { regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2); } else { diff --git a/src/corelib/io/qsettings_winrt.cpp b/src/corelib/io/qsettings_winrt.cpp index 708287ce5e..209b56d920 100644 --- a/src/corelib/io/qsettings_winrt.cpp +++ b/src/corelib/io/qsettings_winrt.cpp @@ -402,7 +402,7 @@ void QWinRTSettingsPrivate::set(const QString &uKey, const QVariant &value) QStringList::const_iterator it = l.constBegin(); bool containsNull = false; for (; it != l.constEnd(); ++it) { - if ((*it).length() == 0 || it->indexOf(QChar::Null) != -1) { + if ((*it).length() == 0 || it->contains(QChar::Null)) { // We can only store as binary containsNull = true; break; @@ -445,7 +445,7 @@ void QWinRTSettingsPrivate::set(const QString &uKey, const QVariant &value) break; default: { const QString s = variantToString(value); - if (s.indexOf(QChar::Null) != -1) { + if (s.contains(QChar::Null)) { hr = valueStatics->CreateUInt8Array(s.length() * 2, (BYTE*) s.utf16(), &val); } else { HStringReference ref((const wchar_t*)s.utf16(), s.size()); -- cgit v1.2.3 From e79b40ee8f78a9669ed0b7b6def2a69ef7ab02fa Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 1 Nov 2016 15:28:17 -0700 Subject: macOS: Clear event dispatcher interrupt state A pending interrupt of a QEventLoop may interfere with native runModal calls, resulting in Cocoa's main event loop to be stopped unexpectedly. After commit 9ab60b9c processEvents() no longer resets the event dispatcher interrupt flag. Add QCocoaEventDispatcher::clearCurrentThreadCocoa EventDispatcherInterruptFlag(). Use it to clear the interrupt state before calling runModal and variants. Work around the inability to use platform API in the print support code. Change-Id: I3e03e7ec21ff6c49442c7a6e803a7200aac0b58d Task-number: QTBUG-56746 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoaeventdispatcher.h | 2 ++ src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 13 +++++++++++++ src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoanativeinterface.h | 2 ++ src/plugins/platforms/cocoa/qcocoanativeinterface.mm | 6 ++++++ src/printsupport/dialogs/qpagesetupdialog_mac.mm | 5 +++++ src/printsupport/dialogs/qprintdialog_mac.mm | 5 +++++ 9 files changed, 48 insertions(+) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 0319d4ca6d..7d12804d47 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -45,6 +45,7 @@ #include "qcocoacolordialoghelper.h" #include "qcocoahelpers.h" +#include "qcocoaeventdispatcher.h" #import @@ -322,6 +323,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); + + // Make sure we don't interrupt the runModalForWindow call. + QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag(); + [NSApp runModalForWindow:mColorPanel]; mDialogIsExecuting = false; return (mResultCode == NSOKButton); diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 84880d51c5..70887c41c9 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -131,6 +131,8 @@ public: void interrupt(); void flush(); + static void clearCurrentThreadCocoaEventDispatcherInterruptFlag(); + friend void qt_mac_maybeCancelWaitForMoreEventsForwarder(QAbstractEventDispatcher *eventDispatcher); }; diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 5c27cf8059..d9c835d797 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -966,6 +966,19 @@ void QCocoaEventDispatcher::interrupt() void QCocoaEventDispatcher::flush() { } +// QTBUG-56746: The behavior of processEvents() has been changed to not clear +// the interrupt flag. Use this function to clear it. + void QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag() +{ + QCocoaEventDispatcher *cocoaEventDispatcher = + qobject_cast(QThread::currentThread()->eventDispatcher()); + if (!cocoaEventDispatcher) + return; + QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = + static_cast(QObjectPrivate::get(cocoaEventDispatcher)); + cocoaEventDispatcherPrivate->interrupt = false; +} + QCocoaEventDispatcher::~QCocoaEventDispatcher() { Q_D(QCocoaEventDispatcher); diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 4eb35f5495..c7191e4841 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -53,6 +53,7 @@ #include "qt_mac_p.h" #include "qcocoahelpers.h" #include "qcocoamenubar.h" +#include "qcocoaeventdispatcher.h" #include #include #include @@ -243,6 +244,10 @@ static QString strippedText(QString s) // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); + + // Make sure we don't interrupt the runModal call below. + QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag(); + QCocoaMenuBar::redirectKnownMenuItemsToFirstResponder(); mReturnCode = [mSavePanel runModal]; QCocoaMenuBar::resetKnownMenuItemsToQt(); diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index dc7dfb788f..d0b76861d8 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -49,6 +49,7 @@ #include "qcocoafontdialoghelper.h" #include "qcocoahelpers.h" +#include "qcocoaeventdispatcher.h" #import @@ -319,6 +320,10 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); + + // Make sure we don't interrupt the runModalForWindow call. + QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag(); + [NSApp runModalForWindow:mFontPanel]; mDialogIsExecuting = false; return (mResultCode == NSOKButton); diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h index 7065a364bf..b06fff1375 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h @@ -100,6 +100,8 @@ private: */ Q_INVOKABLE QPixmap defaultBackgroundPixmapForQWizard(); + Q_INVOKABLE void clearCurrentThreadCocoaEventDispatcherInterruptFlag(); + // QMacPastebardMime support. The mac pasteboard void pointers are // QMacPastebardMime instances from the cocoa plugin or qtmacextras // These two classes are kept in sync and can be casted between. diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 8562246817..a327750ffd 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -44,6 +44,7 @@ #include "qcocoahelpers.h" #include "qcocoaapplication.h" #include "qcocoaintegration.h" +#include "qcocoaeventdispatcher.h" #include #include @@ -194,6 +195,11 @@ QPixmap QCocoaNativeInterface::defaultBackgroundPixmapForQWizard() return QPixmap(); } +void QCocoaNativeInterface::clearCurrentThreadCocoaEventDispatcherInterruptFlag() +{ + QCocoaEventDispatcher::clearCurrentThreadCocoaEventDispatcherInterruptFlag(); +} + void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window) { Q_UNUSED(window); diff --git a/src/printsupport/dialogs/qpagesetupdialog_mac.mm b/src/printsupport/dialogs/qpagesetupdialog_mac.mm index e3e7523a16..c29b911e35 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_mac.mm +++ b/src/printsupport/dialogs/qpagesetupdialog_mac.mm @@ -133,6 +133,11 @@ void QMacPageSetupDialogPrivate::openCocoaPageLayout(Qt::WindowModality modality QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) alloc] initWithNSPrintInfo:printInfo]; if (modality == Qt::ApplicationModal) { + + // Make sure we don't interrupt the runModalWithPrintInfo call. + (void) QMetaObject::invokeMethod(qApp->platformNativeInterface(), + "clearCurrentThreadCocoaEventDispatcherInterruptFlag"); + int rval = [pageLayout runModalWithPrintInfo:printInfo]; [delegate pageLayoutDidEnd:pageLayout returnCode:rval contextInfo:q]; } else { diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm index c16bb93013..c630ab634a 100644 --- a/src/printsupport/dialogs/qprintdialog_mac.mm +++ b/src/printsupport/dialogs/qprintdialog_mac.mm @@ -245,6 +245,11 @@ void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality) if (modality == Qt::ApplicationModal || !q->parentWidget()) { if (modality == Qt::NonModal) qWarning("QPrintDialog is required to be modal on OS X"); + + // Make sure we don't interrupt the runModalWithPrintInfo call. + (void) QMetaObject::invokeMethod(qApp->platformNativeInterface(), + "clearCurrentThreadCocoaEventDispatcherInterruptFlag"); + int rval = [printPanel runModalWithPrintInfo:printInfo]; [delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:q]; } else { -- cgit v1.2.3 From 3654a401f8e046e2fa5a340d0380cc0088a03048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 27 Oct 2016 09:57:54 +0200 Subject: Prevent stale QOpenGLContext fbo pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is logic for clearing the qgl_curent_fbo pointer in release(), but it is not always called, causing the pointer to become stale on QOpenGLFramebufferObject deletion. As a last resort, clear the qgl_curent_fbo pointer on the current context if it’s pointing to the object that is being deleted. Change-Id: I0a91d686cec5fcbe4c1520a9ba96cea833bb2249 Task-number: QTBUG-56639 Reviewed-by: Laszlo Agocs --- src/gui/kernel/qopenglcontext_p.h | 2 +- src/gui/opengl/qopenglframebufferobject.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/kernel/qopenglcontext_p.h b/src/gui/kernel/qopenglcontext_p.h index 2fe8446c65..736f816bfe 100644 --- a/src/gui/kernel/qopenglcontext_p.h +++ b/src/gui/kernel/qopenglcontext_p.h @@ -264,7 +264,7 @@ public: static QOpenGLContextPrivate *get(QOpenGLContext *context) { - return context->d_func(); + return context ? context->d_func() : Q_NULLPTR; } #if !defined(QT_NO_DEBUG) diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 14581c89f6..be5407ccbd 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -955,6 +955,12 @@ QOpenGLFramebufferObject::~QOpenGLFramebufferObject() d->stencil_buffer_guard->free(); if (d->fbo_guard) d->fbo_guard->free(); + + QOpenGLContextPrivate *contextPrv = QOpenGLContextPrivate::get(QOpenGLContext::currentContext()); + if (contextPrv && contextPrv->qgl_current_fbo == this) { + contextPrv->qgl_current_fbo_invalid = true; + contextPrv->qgl_current_fbo = Q_NULLPTR; + } } /*! -- cgit v1.2.3 From d8857f21ac2640215177b9cb7bb681b74bc66068 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 22 Nov 2016 09:46:14 +0100 Subject: If there are no available sizes, then fallback to the requested size In a case like the SVG iconengine there is no available sizes implementation. However in that case we don't need to provide different sizes as we can have SVG scale it for us to the one requested. So it is assumed that with no available sizes implementation that the icon engine will take care of this for us. This ensures that SVG files can be used as icons inside the menu on macOS. Task-number: QTBUG-40225 Task-number: QTBUG-55932 Change-Id: If01ca582c4c07834e6de16652924e0b7e118c87c Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoahelpers.h | 2 +- src/plugins/platforms/cocoa/qcocoahelpers.mm | 7 +++++-- src/plugins/platforms/cocoa/qcocoamenuitem.mm | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index c2abe4e245..bbb37937d2 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -64,7 +64,7 @@ inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qst NSImage *qt_mac_cgimage_to_nsimage(CGImageRef iamge); NSImage *qt_mac_create_nsimage(const QPixmap &pm); -NSImage *qt_mac_create_nsimage(const QIcon &icon); +NSImage *qt_mac_create_nsimage(const QIcon &icon, int defaultSize = 0); CGImageRef qt_mac_toCGImage(const QImage &qImage); CGImageRef qt_mac_toCGImageMask(const QImage &qImage); QImage qt_mac_toQImage(CGImageRef image); diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 058209da7e..cd73148752 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -152,13 +152,16 @@ NSImage *qt_mac_create_nsimage(const QPixmap &pm) return nsImage; } -NSImage *qt_mac_create_nsimage(const QIcon &icon) +NSImage *qt_mac_create_nsimage(const QIcon &icon, int defaultSize) { if (icon.isNull()) return nil; NSImage *nsImage = [[NSImage alloc] init]; - foreach (QSize size, icon.availableSizes()) { + QList availableSizes = icon.availableSizes(); + if (availableSizes.isEmpty() && defaultSize > 0) + availableSizes << QSize(defaultSize, defaultSize); + foreach (QSize size, availableSizes) { QPixmap pm = icon.pixmap(size); QImage image = pm.toImage(); CGImageRef cgImage = qt_mac_toCGImage(image); diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 2d4073956a..fa8eb22569 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -348,7 +348,7 @@ NSMenuItem *QCocoaMenuItem::sync() NSImage *img = nil; if (!m_icon.isNull()) { - img = qt_mac_create_nsimage(m_icon); + img = qt_mac_create_nsimage(m_icon, m_iconSize); [img setSize:NSMakeSize(m_iconSize, m_iconSize)]; } [m_native setImage:img]; -- cgit v1.2.3 From 389b4ec28b6bb402d3575ff9c648ef878257ea84 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 22 Nov 2016 15:45:36 +0100 Subject: Windows QPA: Do not send key events for mouse-synthesized app commands Sending key events in addition causes applications to respond twice to for example the back / forward extra mouse buttons. Suppress the keypress by checking on the device. This is in line with the other platforms, which do not send keypresses either. Native event filters will still be able to listen for WM_APPCOMMAND. Task-number: QTBUG-48117 Task-number: QTBUG-57198 Change-Id: I219e17244087663f06ab2c5a8cf4b880c3655700 Reviewed-by: Andy Shaw --- src/plugins/platforms/windows/qwindowskeymapper.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 60361e436d..a52ae7c2a9 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -861,6 +861,9 @@ bool QWindowsKeyMapper::translateKeyEvent(QWindow *widget, HWND hwnd, bool QWindowsKeyMapper::translateMultimediaKeyEventInternal(QWindow *window, const MSG &msg) { #if defined(WM_APPCOMMAND) + // QTBUG-57198, do not send mouse-synthesized commands as key events in addition + if (GET_DEVICE_LPARAM(msg.lParam) == FAPPCOMMAND_MOUSE) + return false; const int cmd = GET_APPCOMMAND_LPARAM(msg.lParam); const int dwKeys = GET_KEYSTATE_LPARAM(msg.lParam); int state = 0; -- cgit v1.2.3 From d3ab4a1ce7cd0fe6539d592138a8119dd51d818f Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 16 Nov 2016 13:11:43 +0100 Subject: _q_networkSessionClosed - disconnect the correct object We have: ... auto networkSession = getNetworkSession(); ... getNetworkSession() can return non-null pointer even if networkSessionStrongRef is null: ... if (networkSessionStrongRef) return networkSessionStrongRef; return networkSessionWeakRef.toStrongRef(); .... We check the result: if (networkSession) { // here we disconnect signals } But we should use the same networkSession when disconnecting, not start using networkSessionStrongRef suddenly, since it can be null. Task-number: QTBUG-57110 Change-Id: I96babb42c2182e741e6eabaf7d1abb88869861f4 Reviewed-by: Jesus Fernandez Reviewed-by: Edward Welbourne Reviewed-by: Timur Pocheptsov --- src/network/access/qnetworkaccessmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index b649aba4a8..57d110ed94 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1599,7 +1599,7 @@ void QNetworkAccessManagerPrivate::_q_networkSessionClosed() QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed())); QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)), q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State))); - QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)), + QObject::disconnect(networkSession.data(), SIGNAL(error(QNetworkSession::SessionError)), q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError))); networkSessionStrongRef.clear(); -- cgit v1.2.3 From a4bd635b33d08a4b58fb4db8cefd1e0535fb95eb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 21 Nov 2016 17:05:49 +0100 Subject: Typo fix in QDateTime::toString() documentation Text that should simply have been naming days of the week used Qt::Sunday rather than the simple day name. Change-Id: I64a3cdacd854c1c9c0fbf2d11826555086d674f4 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 3e29b55666..5f5023e8b5 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3611,7 +3611,7 @@ QString QDateTime::toString(Qt::DateFormat format) const \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li dddd - \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). + \li the long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li M \li the month as number without a leading zero (1-12) \row \li MM \li the month as number with a leading zero (01-12) -- cgit v1.2.3 From 0aa3de46cacacdb83efe1d5e5b2506560c93c9ff Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 7 Nov 2016 10:09:06 +0100 Subject: Fix two leaky uses of realloc() If it fails, we get NULL back but haven't free()d the old pointer; saving the NULL return over the old pointer forgets it, leaking the memory it pointed to. This is particularly severe in the JSON parser's grow(), where reading a very large JSON document can lead to the last successful realloc() in a doubling pattern being very large indeed; the subsequent failure will leak this very last allocation. Only worth checking for, however, when the subsequent code takes care to handle failure: in most cases, if realloc() fails, we're about to crash anyway. Change-Id: Icd3a503f169be224f0a058c58e8b7c82a3241ae7 Reviewed-by: Marc Mutz Reviewed-by: Anton Kudryavtsev --- src/corelib/json/qjsonparser.cpp | 5 +++-- src/corelib/json/qjsonparser_p.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp index c7b16d5ec9..a23741a85c 100644 --- a/src/corelib/json/qjsonparser.cpp +++ b/src/corelib/json/qjsonparser.cpp @@ -491,9 +491,10 @@ namespace { memcpy(newValues, data, size*sizeof(QJsonPrivate::Value)); data = newValues; } else { - data = static_cast(realloc(data, alloc*sizeof(QJsonPrivate::Value))); - if (!data) + void *newValues = realloc(data, alloc * sizeof(QJsonPrivate::Value)); + if (!newValues) return false; + data = static_cast(newValues); } return true; } diff --git a/src/corelib/json/qjsonparser_p.h b/src/corelib/json/qjsonparser_p.h index 82a7899a51..b17d75fb3a 100644 --- a/src/corelib/json/qjsonparser_p.h +++ b/src/corelib/json/qjsonparser_p.h @@ -101,11 +101,12 @@ private: inline int reserveSpace(int space) { if (current + space >= dataLength) { dataLength = 2*dataLength + space; - data = (char *)realloc(data, dataLength); - if (!data) { + char *newData = (char *)realloc(data, dataLength); + if (!newData) { lastError = QJsonParseError::DocumentTooLarge; return -1; } + data = newData; } int pos = current; current += space; -- cgit v1.2.3 From 7c41ced98c3cb5484069c14c45733d3129e7945a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 2 Feb 2016 17:35:09 +0100 Subject: QDateTimeParser: introduce at least some encapsulation Shuffled its parts to make clear which bits are public, private and protected. QDateTimeEditPrivate makes rather heavy use of the last. Change-Id: Ic5f9d0c5cc85f02e57d3f31e9ac31a17428c5311 Reviewed-by: Timur Pocheptsov --- src/corelib/tools/qdatetimeparser_p.h | 81 ++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index 90c6a8acba..0ac7532aed 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -97,14 +97,6 @@ public: none.zeroesAdded = 0; } virtual ~QDateTimeParser() {} - enum AmPmFinder { - Neither = -1, - AM = 0, - PM = 1, - PossibleAM = 2, - PossiblePM = 3, - PossibleBoth = 4 - }; enum Section { NoSection = 0x00000, @@ -180,62 +172,75 @@ public: #ifndef QT_NO_DATESTRING StateNode parse(QString &input, int &cursorPosition, const QDateTime ¤tValue, bool fixup) const; #endif - int sectionMaxSize(int index) const; - int sectionSize(int index) const; - int sectionMaxSize(Section s, int count) const; - int sectionPos(int index) const; - int sectionPos(const SectionNode &sn) const; - - const SectionNode §ionNode(int index) const; - Section sectionType(int index) const; - QString sectionText(int sectionIndex) const; - QString sectionText(const QString &text, int sectionIndex, int index) const; - int getDigit(const QDateTime &dt, int index) const; - bool setDigit(QDateTime &t, int index, int newval) const; - int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, - int index, QDateTimeParser::State &state, int *used = 0) const; - int absoluteMax(int index, const QDateTime &value = QDateTime()) const; - int absoluteMin(int index) const; bool parseFormat(const QString &format); #ifndef QT_NO_DATESTRING bool fromString(const QString &text, QDate *date, QTime *time) const; #endif + enum FieldInfoFlag { + Numeric = 0x01, + FixedWidth = 0x02, + AllowPartial = 0x04, + Fraction = 0x08 + }; + Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) + + FieldInfo fieldInfo(int index) const; + + void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } + virtual QString displayText() const { return text; } + +private: + int sectionMaxSize(Section s, int count) const; + QString sectionText(const QString &text, int sectionIndex, int index) const; + int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, + int index, QDateTimeParser::State &state, int *used = 0) const; #ifndef QT_NO_TEXTDATE int findMonth(const QString &str1, int monthstart, int sectionIndex, QString *monthName = 0, int *used = 0) const; int findDay(const QString &str1, int intDaystart, int sectionIndex, QString *dayName = 0, int *used = 0) const; #endif + + enum AmPmFinder { + Neither = -1, + AM = 0, + PM = 1, + PossibleAM = 2, + PossiblePM = 3, + PossibleBoth = 4 + }; AmPmFinder findAmPm(QString &str, int index, int *used = 0) const; bool potentialValue(const QString &str, int min, int max, int index, const QDateTime ¤tValue, int insert) const; - bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const; - QString stateName(State s) const; +protected: // for the benefit of QDateTimeEditPrivate + int sectionSize(int index) const; + int sectionMaxSize(int index) const; + int sectionPos(int index) const; + int sectionPos(const SectionNode &sn) const; - enum FieldInfoFlag { - Numeric = 0x01, - FixedWidth = 0x02, - AllowPartial = 0x04, - Fraction = 0x08 - }; - Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) + const SectionNode §ionNode(int index) const; + Section sectionType(int index) const; + QString sectionText(int sectionIndex) const; + int getDigit(const QDateTime &dt, int index) const; + bool setDigit(QDateTime &t, int index, int newval) const; - FieldInfo fieldInfo(int index) const; + int absoluteMax(int index, const QDateTime &value = QDateTime()) const; + int absoluteMin(int index) const; - void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } + bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const; + QString stateName(State s) const; virtual QDateTime getMinimum() const; virtual QDateTime getMaximum() const; virtual int cursorPosition() const { return -1; } - virtual QString displayText() const { return text; } virtual QString getAmPmText(AmPm ap, Case cs) const; virtual QLocale locale() const { return defaultLocale; } mutable int currentSectionIndex; Sections display; /* - This stores the stores the most recently selected day. + This stores the most recently selected day. It is useful when considering the following scenario: 1. Date is: 31/01/2000 @@ -255,9 +260,7 @@ public: QString displayFormat; QLocale defaultLocale; QVariant::Type parserType; - bool fixday; - Qt::TimeSpec spec; // spec if used by QDateTimeEdit Context context; }; -- cgit v1.2.3 From 4f896ba34e0f56e492da19c6d1353ac4ba4c7b2e Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Wed, 23 Nov 2016 11:39:31 +0100 Subject: ICC: Fix MySQL driver build In function `QMYSQLDriver::formatValue(QSqlField const&, bool) const': qsql_mysql.cpp:1569: undefined reference to `QString::operator=( QLatin1String) Change-Id: I56104cdd53fdc083670510f24b735cf05948f156 Reviewed-by: Samuel Gaist Reviewed-by: Milian Wolff Reviewed-by: Thiago Macieira --- src/sql/drivers/mysql/qsql_mysql.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index c26c03ad07..4e86a0bd4e 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -1566,7 +1566,7 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons Q_D(const QMYSQLDriver); QString r; if (field.isNull()) { - r = QLatin1String("NULL"); + r = QStringLiteral("NULL"); } else { switch(field.type()) { case QVariant::Double: -- cgit v1.2.3 From 5bd2d6afec935a9eb4cf39af830f450f89f7202a Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 24 Nov 2016 10:54:03 +0200 Subject: Remove nokia reference in example mimetype Change-Id: I45c01fd57171f4ba6ea195d7ad3ae988a1797acb Reviewed-by: Oswald Buddenhagen Reviewed-by: David Faure --- src/corelib/mimetypes/qmimedatabase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp index 5c272d420b..91b50494d0 100644 --- a/src/corelib/mimetypes/qmimedatabase.cpp +++ b/src/corelib/mimetypes/qmimedatabase.cpp @@ -257,7 +257,7 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent) \code - + Qt qmake Profile -- cgit v1.2.3