From 6f0065944dc3c638553519bc7d4883f2cca6e04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Mon, 26 Mar 2012 10:04:21 +0200 Subject: Hide QTypeModuleInfo in a private namespace. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The class is private and shouldn't pollute global namespace. Change-Id: Ib44473fd72e5a70096eeff1662e88b29263d19c6 Reviewed-by: João Abecasis --- src/corelib/kernel/qmetatype.cpp | 30 +++++++++++++++--------------- src/corelib/kernel/qmetatype_p.h | 2 +- src/corelib/kernel/qvariant.cpp | 2 +- src/gui/kernel/qguivariant.cpp | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index fba1aaf9b6..1207d995b0 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -82,7 +82,7 @@ namespace { struct DefinedTypesFilter { template struct Acceptor { - static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition::IsAvailable && QTypeModuleInfo::IsCore; + static const bool IsAccepted = QtMetaTypePrivate::TypeDefinition::IsAvailable && QModulesPrivate::QTypeModuleInfo::IsCore; }; }; } // namespace @@ -1061,11 +1061,11 @@ class TypeCreator { struct CreatorImpl { static void *Create(const int type, const void *copy) { - if (QTypeModuleInfo::IsGui) { + if (QModulesPrivate::QTypeModuleInfo::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].creator(copy); } - if (QTypeModuleInfo::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].creator(copy); } @@ -1123,12 +1123,12 @@ class TypeDestroyer { struct DestroyerImpl { static void Destroy(const int type, void *where) { - if (QTypeModuleInfo::IsGui) { + if (QModulesPrivate::QTypeModuleInfo::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where); return; } - if (QTypeModuleInfo::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where); return; @@ -1189,10 +1189,10 @@ class TypeConstructor { struct ConstructorImpl { static void *Construct(const int type, void *where, const void *copy) { - if (QTypeModuleInfo::IsGui) + if (QModulesPrivate::QTypeModuleInfo::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0; - if (QTypeModuleInfo::IsWidget) + if (QModulesPrivate::QTypeModuleInfo::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0; // This point can be reached only for known types that definition is not available, for example @@ -1277,12 +1277,12 @@ class TypeDestructor { struct DestructorImpl { static void Destruct(const int type, void *where) { - if (QTypeModuleInfo::IsGui) { + if (QModulesPrivate::QTypeModuleInfo::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where); return; } - if (QTypeModuleInfo::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where); return; @@ -1350,10 +1350,10 @@ class SizeOf { struct SizeOfImpl { static int Size(const int type) { - if (QTypeModuleInfo::IsGui) + if (QModulesPrivate::QTypeModuleInfo::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0; - if (QTypeModuleInfo::IsWidget) + if (QModulesPrivate::QTypeModuleInfo::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0; // This point can be reached only for known types that definition is not available, for example @@ -1418,10 +1418,10 @@ class Flags { static quint32 Flags(const int type) { - if (QTypeModuleInfo::IsGui) + if (QModulesPrivate::QTypeModuleInfo::IsGui) return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0; - if (QTypeModuleInfo::IsWidget) + if (QModulesPrivate::QTypeModuleInfo::IsWidget) return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0; // This point can be reached only for known types that definition is not available, for example @@ -1601,12 +1601,12 @@ class TypeInfo { { TypeInfoImpl(const uint type, QMetaTypeInterface &info) { - if (QTypeModuleInfo::IsGui) { + if (QModulesPrivate::QTypeModuleInfo::IsGui) { if (Q_LIKELY(qMetaTypeGuiHelper)) info = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType]; return; } - if (QTypeModuleInfo::IsWidget) { + if (QModulesPrivate::QTypeModuleInfo::IsWidget) { if (Q_LIKELY(qMetaTypeWidgetsHelper)) info = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType]; return; diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 2ab4a3896f..74229d3f3c 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -70,7 +70,6 @@ static inline int moduleForType(const int typeId) return Widgets; return Unknown; } -} template class QTypeModuleInfo @@ -114,6 +113,7 @@ QT_FOR_EACH_STATIC_CORE_CLASS(QT_DECLARE_CORE_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_DECLARE_CORE_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_GUI_CLASS(QT_DECLARE_GUI_MODULE_TYPES_ITER) QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_DECLARE_WIDGETS_MODULE_TYPES_ITER) +} // namespace QModulesPrivate #undef QT_DECLARE_CORE_MODULE_TYPES_ITER #undef QT_DECLARE_GUI_MODULE_TYPES_ITER diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 82e0435d0a..7b0fab887b 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -103,7 +103,7 @@ namespace { struct CoreTypesFilter { template struct Acceptor { - static const bool IsAccepted = QTypeModuleInfo::IsCore && QtMetaTypePrivate::TypeDefinition::IsAvailable; + static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo::IsCore && QtMetaTypePrivate::TypeDefinition::IsAvailable; }; }; } // annonymous diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 436688a295..44dc2d27ca 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -101,7 +101,7 @@ namespace { struct GuiTypesFilter { template struct Acceptor { - static const bool IsAccepted = QTypeModuleInfo::IsGui && QtMetaTypePrivate::TypeDefinition::IsAvailable; + static const bool IsAccepted = QModulesPrivate::QTypeModuleInfo::IsGui && QtMetaTypePrivate::TypeDefinition::IsAvailable; }; }; -- cgit v1.2.3 From ab0bcd0792af76a938f8665c9c1082d9b9eb3c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 3 Apr 2012 15:12:47 +0200 Subject: Remove redundant checks in QVariant. QVariant and QMetaType have aligned type naming implementation. Change-Id: I9eaae1045c492c148e3e9d23f4e04d48272f7ec2 Reviewed-by: Stephen Kelly --- src/corelib/kernel/qvariant.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 7b0fab887b..179a33ca6e 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1582,9 +1582,6 @@ void QVariant::clear() */ const char *QVariant::typeToName(int typeId) { - if (typeId == Invalid) - return 0; - return QMetaType::typeName(typeId); } @@ -1598,9 +1595,6 @@ const char *QVariant::typeToName(int typeId) */ QVariant::Type QVariant::nameToType(const char *name) { - if (!name || !*name) - return Invalid; - int metaType = QMetaType::type(name); return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType; } -- cgit v1.2.3 From 9ecce11261e35686afa736bd31431386c89f59ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 3 Apr 2012 15:33:47 +0200 Subject: Remove redundant check in QMetaType::typeInfo The check was introduced when void was not a fully defined type. Change-Id: I4df8607999436f8db92be77fc8fd203fc66c2816 Reviewed-by: Stephen Kelly --- src/corelib/kernel/qmetatype.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 1207d995b0..53b22958c3 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1623,7 +1623,6 @@ public: } template void delegate(const T*) { TypeInfoImpl(m_type, info); } - void delegate(const void*) {} void delegate(const QMetaTypeSwitcher::UnknownType*) {} void delegate(const QMetaTypeSwitcher::NotBuiltinType*) { customTypeInfo(m_type); } private: @@ -1645,7 +1644,7 @@ QMetaType QMetaType::typeInfo(const int type) { TypeInfo typeInfo(type); QMetaTypeSwitcher::switcher(typeInfo, type, 0); - return typeInfo.info.creator || type == Void ? QMetaType(QMetaType::NoExtensionFlags + return typeInfo.info.creator ? QMetaType(QMetaType::NoExtensionFlags , static_cast(0) // typeInfo::info is a temporary variable, we can't return address of it. , typeInfo.info.creator , typeInfo.info.deleter -- cgit v1.2.3 From 21102a71ff9da746b9d46b706ea2f23cfca6eb6f Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 17 Apr 2012 17:33:40 -0700 Subject: api: QGuiApplication::inputMethod should be static Pretty much all methods in QGuiApplication are static. Also adds documentation. Change-Id: I96808dd266922432b92fe3962292e4d5b6a8ab46 Reviewed-by: Pekka Vuorela --- src/gui/kernel/qguiapplication.cpp | 18 +++++++++++++----- src/gui/kernel/qguiapplication.h | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 9ffc35a608..8cbf55de05 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2166,12 +2166,20 @@ bool QGuiApplication::desktopSettingsAware() return QGuiApplicationPrivate::obey_desktop_settings; } -QInputMethod *QGuiApplication::inputMethod() const +/*! + returns the input method. + + The input method returns properties about the state and position of + the virtual keyboard. It also provides information about the position of the + current focused input element. + + \sa QInputPanel + */ +QInputMethod *QGuiApplication::inputMethod() { - Q_D(const QGuiApplication); - if (!d->inputMethod) - const_cast(d)->inputMethod = new QInputMethod(); - return d->inputMethod; + if (!qGuiApp->d_func()->inputMethod) + qGuiApp->d_func()->inputMethod = new QInputMethod(); + return qGuiApp->d_func()->inputMethod; } /*! diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 75a0f6cd4b..2a1ea3d9de 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -131,7 +131,7 @@ public: static bool desktopSettingsAware(); QT_DEPRECATED QInputPanel *inputPanel() const; - QInputMethod *inputMethod() const; + static QInputMethod *inputMethod(); static QPlatformNativeInterface *platformNativeInterface(); -- cgit v1.2.3 From 10c88faf79de45f86a0826d104e202b4e12eba6b Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 13 Apr 2012 09:25:23 -0700 Subject: api: remove QWindow::visible() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The correct api is QWindow::isVisible(). Removing the api is safe since QWindow is not even released yet. Only qtdeclarative needed to be fixed with 71c8fe296fe5aa7e79033dd8f5b539852d4276e0. Change-Id: Ie571ed4802fe89132419e402acdb854446f4578f Reviewed-by: Samuel Rødal --- src/gui/kernel/qwindow.cpp | 9 --------- src/gui/kernel/qwindow.h | 2 -- src/plugins/platforms/directfb/qdirectfbwindow.cpp | 4 ++-- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index b042283071..2117835609 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -264,15 +264,6 @@ void QWindow::setVisible(bool visible) } } -/*! - Returns true if the window is set to visible. - \obsolete -*/ -bool QWindow::visible() const -{ - return isVisible(); -} - bool QWindow::isVisible() const { Q_D(const QWindow); diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index 118e3ec25f..e99c062158 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -102,8 +102,6 @@ public: void setSurfaceType(SurfaceType surfaceType); SurfaceType surfaceType() const; - QT_DEPRECATED bool visible() const; - bool isVisible() const; void create(); diff --git a/src/plugins/platforms/directfb/qdirectfbwindow.cpp b/src/plugins/platforms/directfb/qdirectfbwindow.cpp index dd2d4e488c..a830f1e3db 100644 --- a/src/plugins/platforms/directfb/qdirectfbwindow.cpp +++ b/src/plugins/platforms/directfb/qdirectfbwindow.cpp @@ -87,7 +87,7 @@ QDirectFbWindow::QDirectFbWindow(QWindow *tlw, QDirectFbInput *inputhandler) m_dfbWindow->SetOpacity(m_dfbWindow.data(), 0xff); - setVisible(window()->visible()); + setVisible(window()->isVisible()); m_inputHandler->addWindow(m_dfbWindow.data(), tlw); } @@ -103,7 +103,7 @@ void QDirectFbWindow::setGeometry(const QRect &rect) // bool isMoveOnly = (rect.topLeft() != geometry().topLeft()) && (rect.size() == geometry().size()); QPlatformWindow::setGeometry(rect); - if (window()->visible()) { + if (window()->isVisible()) { m_dfbWindow->SetBounds(m_dfbWindow.data(), rect.x(),rect.y(), rect.width(), rect.height()); // ### TODO port, verify if this is needed -- cgit v1.2.3 From ff55d64f6788563a6ef9da2b6d0b6dc23bb936aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Fri, 13 Apr 2012 14:52:34 +0200 Subject: Remove QVariant constructor taking Qt::GlobalColor. The constructor is wrong, it creates instance of QVariant encapsulating a QColor instance. QVariant should not implicitly convert data, never. Change-Id: Idc794ecdecb42d8b53fee3f993bf51ddd43f595d Reviewed-by: Lars Knoll --- dist/changes-5.0.0 | 6 ++++++ src/corelib/kernel/qvariant.cpp | 14 -------------- src/corelib/kernel/qvariant.h | 1 - src/gui/kernel/qguivariant.cpp | 9 --------- tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp | 2 +- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 9 --------- 6 files changed, 7 insertions(+), 34 deletions(-) diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0 index d3ea3fbcb3..9cef238cff 100644 --- a/dist/changes-5.0.0 +++ b/dist/changes-5.0.0 @@ -68,6 +68,12 @@ information about a particular change. method returns void is to compare the return value of QMetaMethod::returnType() to QMetaType::Void. +- QVariant: + * Inconsistent constructor taking Qt::GlobalColor and producing QVariant(QColor) + instance was removed. Code constructing such variants can be migrated by + explicitly calling QColor constructor. For example from "QVariant(Qt::red)" + to "QVariant(QColor(Qt::red))" + - QTestLib: * The plain-text, xml and lightxml test output formats have been changed to show a test result for every row of test data in data-driven tests. In diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 179a33ca6e..10b86bcb48 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1349,19 +1349,6 @@ QVariant::QVariant(const char *val) Constructs a new variant with the regular expression value \a re. */ -/*! \since 4.2 - \fn QVariant::QVariant(Qt::GlobalColor color) - - Constructs a new variant of type QVariant::Color and initializes - it with \a color. - - This is a convenience constructor that allows \c{QVariant(Qt::blue);} - to create a valid QVariant storing a QColor. - - Note: This constructor will assert if the application does not link - to the Qt GUI library. - */ - QVariant::QVariant(Type type) { create(type, 0); } QVariant::QVariant(int typeId, const void *copy) @@ -1443,7 +1430,6 @@ QVariant::QVariant(const QRegExp ®Exp) { d.is_null = false; d.type = RegExp; QVariant::QVariant(const QRegularExpression &re) { d.is_null = false; d.type = QMetaType::QRegularExpression; v_construct(&d, re); } #endif // QT_BOOTSTRAPPED #endif // QT_NO_REGEXP -QVariant::QVariant(Qt::GlobalColor color) { create(62, &color); } /*! Returns the storage type of the value stored in the variant. diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fb0e059f45..cd8ac9823d 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -248,7 +248,6 @@ class Q_CORE_EXPORT QVariant QVariant(const QUrl &url); QVariant(const QEasingCurve &easing); #endif - QVariant(Qt::GlobalColor color); QVariant& operator=(const QVariant &other); #ifdef Q_COMPILER_RVALUE_REFS diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 44dc2d27ca..9d1294d588 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -108,15 +108,6 @@ struct GuiTypesFilter { static void construct(QVariant::Private *x, const void *copy) { const int type = x->type; - if (Q_UNLIKELY(type == 62)) { - // small 'trick' to let a QVariant(Qt::blue) create a variant - // of type QColor - // TODO Get rid of this hack. - x->type = QVariant::Color; - QColor color(*reinterpret_cast(copy)); - v_construct(x, &color); - return; - } QVariantConstructor constructor(x, copy); QMetaTypeSwitcher::switcher(constructor, type, 0); } diff --git a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp index f9a6bae087..dc9fc19a21 100644 --- a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp +++ b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp @@ -97,7 +97,7 @@ void tst_QMimeData::colorData() const QCOMPARE(qvariant_cast(mimeData.colorData()), red); // change, verify - mimeData.setColorData(Qt::blue); + mimeData.setColorData(QColor(Qt::blue)); QVERIFY(mimeData.hasColor()); QCOMPARE(qvariant_cast(mimeData.colorData()), blue); } diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 6a6460d17b..7d821f038b 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -235,8 +235,6 @@ private slots: void saveLoadCustomTypes(); - void globalColor(); - void variantMap(); void variantHash(); @@ -2447,13 +2445,6 @@ void tst_QVariant::url() QCOMPARE(v3.toString(), str); } -void tst_QVariant::globalColor() -{ - QVariant variant(Qt::blue); - QVERIFY(variant.type() == QVariant::Color); - QVERIFY(qVariantValue(variant) == QColor(Qt::blue)); -} - void tst_QVariant::variantMap() { QMap map; -- cgit v1.2.3 From 275945f1449b3ff4e7421ab65a38b885cb338152 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Apr 2012 11:25:38 -0300 Subject: Add an assertion to deleteLater() before it modifies QEvent::d The deferred deletion functionality stores the event loop level nesting count in the QEvent d pointer. In Qt 4, this d pointer was not usable because we forgot to add a proper copy constructor and assignment operator to it, so the deleteLater() process stored the count here safely. Since Qt 5 now has non-implicit copy methods, the d pointer could be used in the future. If QEvent uses it, this assertion will trigger. Note that it doesn't apply to classes derived from QEvent, though. Change-Id: I8600c8e9379921e32aca166bc0a6c0b4c4ed799f Reviewed-by: Bradley T. Hughes --- src/corelib/kernel/qcoreapplication.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 7b26a01cbf..56674bc08e 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1074,6 +1074,12 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) if (event->type() == QEvent::DeferredDelete && data == QThreadData::current()) { // remember the current running eventloop for DeferredDelete // events posted in the receiver's thread + + // check that QEvent's d pointer is unused before we store the loop level + // if further updates to QEvent have made the use of the d pointer necessary, + // then update this code to store the loop level somewhere else + Q_ASSERT_X(event->d == 0, "QCoreApplication::postEvent", + "Internal error: this code relies on QEvent::d being null"); event->d = reinterpret_cast(quintptr(data->loopLevel)); } -- cgit v1.2.3 From a3f90fd44f822ae9d77c9d115934e18a9c7466fd Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Apr 2012 17:07:28 -0300 Subject: Remove private classes in QEvent-derived classes. QEventPrivate doesn't exist, so these classes were technically abusing the d pointer. Move the contents of the private classes into the main event classes. Change-Id: If2e894c1fa05f468221a0b43f3ebdf90769298eb Reviewed-by: Gunnar Sletta Reviewed-by: Lars Knoll --- src/gui/kernel/qevent.cpp | 106 ++++++++-------------------------------------- src/gui/kernel/qevent.h | 23 +++++----- src/gui/kernel/qevent_p.h | 51 ---------------------- 3 files changed, 30 insertions(+), 150 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 505e89b44d..7f1a850cda 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -2787,19 +2787,14 @@ QShowEvent::~QShowEvent() \note This class is currently supported for Mac OS X only. */ -QFileOpenEventPrivate::~QFileOpenEventPrivate() -{ -} - /*! \internal Constructs a file open event for the given \a file. */ QFileOpenEvent::QFileOpenEvent(const QString &file) - : QEvent(FileOpen), f(file) + : QEvent(FileOpen), f(file), m_url(QUrl::fromLocalFile(file)) { - d = reinterpret_cast(new QFileOpenEventPrivate(QUrl::fromLocalFile(file))); } /*! @@ -2808,10 +2803,8 @@ QFileOpenEvent::QFileOpenEvent(const QString &file) Constructs a file open event for the given \a url. */ QFileOpenEvent::QFileOpenEvent(const QUrl &url) - : QEvent(FileOpen) + : QEvent(FileOpen), f(url.toLocalFile()), m_url(url) { - d = reinterpret_cast(new QFileOpenEventPrivate(url)); - f = url.toLocalFile(); } @@ -2819,7 +2812,6 @@ QFileOpenEvent::QFileOpenEvent(const QUrl &url) */ QFileOpenEvent::~QFileOpenEvent() { - delete reinterpret_cast(d); } /*! @@ -2835,10 +2827,6 @@ QFileOpenEvent::~QFileOpenEvent() \since 4.6 */ -QUrl QFileOpenEvent::url() const -{ - return reinterpret_cast(d)->url; -} /*! \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const @@ -4065,10 +4053,8 @@ void QTouchEvent::TouchPoint::setFlags(InfoFlags flags) The \a startPos is the position of a touch or mouse event that started the scrolling. */ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos) - : QEvent(QEvent::ScrollPrepare) + : QEvent(QEvent::ScrollPrepare), m_target(0), m_startPos(startPos) { - d = reinterpret_cast(new QScrollPrepareEventPrivate()); - d_func()->startPos = startPos; } /*! @@ -4076,7 +4062,6 @@ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos) */ QScrollPrepareEvent::~QScrollPrepareEvent() { - delete reinterpret_cast(d); } /*! @@ -4084,7 +4069,7 @@ QScrollPrepareEvent::~QScrollPrepareEvent() */ QPointF QScrollPrepareEvent::startPos() const { - return d_func()->startPos; + return m_startPos; } /*! @@ -4094,7 +4079,7 @@ QPointF QScrollPrepareEvent::startPos() const */ QSizeF QScrollPrepareEvent::viewportSize() const { - return d_func()->viewportSize; + return m_viewportSize; } /*! @@ -4102,7 +4087,7 @@ QSizeF QScrollPrepareEvent::viewportSize() const */ QRectF QScrollPrepareEvent::contentPosRange() const { - return d_func()->contentPosRange; + return m_contentPosRange; } /*! @@ -4110,7 +4095,7 @@ QRectF QScrollPrepareEvent::contentPosRange() const */ QPointF QScrollPrepareEvent::contentPos() const { - return d_func()->contentPos; + return m_contentPos; } @@ -4121,7 +4106,7 @@ QPointF QScrollPrepareEvent::contentPos() const */ void QScrollPrepareEvent::setViewportSize(const QSizeF &size) { - d_func()->viewportSize = size; + m_viewportSize = size; } /*! @@ -4131,7 +4116,7 @@ void QScrollPrepareEvent::setViewportSize(const QSizeF &size) */ void QScrollPrepareEvent::setContentPosRange(const QRectF &rect) { - d_func()->contentPosRange = rect; + m_contentPosRange = rect; } /*! @@ -4141,26 +4126,10 @@ void QScrollPrepareEvent::setContentPosRange(const QRectF &rect) */ void QScrollPrepareEvent::setContentPos(const QPointF &pos) { - d_func()->contentPos = pos; + m_contentPos = pos; } -/*! - \internal -*/ -QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() -{ - return reinterpret_cast(d); -} - -/*! - \internal -*/ -const QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() const -{ - return reinterpret_cast(d); -} - /*! \class QScrollEvent \since 4.8 @@ -4198,12 +4167,8 @@ const QScrollPrepareEventPrivate *QScrollPrepareEvent::d_func() const event is the first one, the last one or some event in between. */ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState) - : QEvent(QEvent::Scroll) + : QEvent(QEvent::Scroll), m_contentPos(contentPos), m_overshoot(overshootDistance), m_state(scrollState) { - d = reinterpret_cast(new QScrollEventPrivate()); - d_func()->contentPos = contentPos; - d_func()->overshoot= overshootDistance; - d_func()->state = scrollState; } /*! @@ -4211,7 +4176,6 @@ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDi */ QScrollEvent::~QScrollEvent() { - delete reinterpret_cast(d); } /*! @@ -4219,7 +4183,7 @@ QScrollEvent::~QScrollEvent() */ QPointF QScrollEvent::contentPos() const { - return d_func()->contentPos; + return m_contentPos; } /*! @@ -4230,7 +4194,7 @@ QPointF QScrollEvent::contentPos() const */ QPointF QScrollEvent::overshootDistance() const { - return d_func()->overshoot; + return m_overshoot; } /*! @@ -4243,23 +4207,7 @@ QPointF QScrollEvent::overshootDistance() const */ QScrollEvent::ScrollState QScrollEvent::scrollState() const { - return d_func()->state; -} - -/*! - \internal -*/ -QScrollEventPrivate *QScrollEvent::d_func() -{ - return reinterpret_cast(d); -} - -/*! - \internal -*/ -const QScrollEventPrivate *QScrollEvent::d_func() const -{ - return reinterpret_cast(d); + return m_state; } /*! @@ -4267,11 +4215,8 @@ const QScrollEventPrivate *QScrollEvent::d_func() const \a orientation is the new orientation of the screen. */ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation) - : QEvent(QEvent::OrientationChange) + : QEvent(QEvent::OrientationChange), m_screen(screen), m_orientation(screenOrientation) { - d = reinterpret_cast(new QScreenOrientationChangeEventPrivate()); - d_func()->screen = screen; - d_func()->orientation = screenOrientation; } /*! @@ -4279,7 +4224,6 @@ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt */ QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() { - delete reinterpret_cast(d); } /*! @@ -4287,7 +4231,7 @@ QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() */ QScreen *QScreenOrientationChangeEvent::screen() const { - return d_func()->screen; + return m_screen; } /*! @@ -4295,23 +4239,7 @@ QScreen *QScreenOrientationChangeEvent::screen() const */ Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const { - return d_func()->orientation; -} - -/*! - \internal -*/ -QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() -{ - return reinterpret_cast(d); -} - -/*! - \internal -*/ -const QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() const -{ - return reinterpret_cast(d); + return m_orientation; } QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 7761bab944..de4befb64c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -646,10 +647,11 @@ public: ~QFileOpenEvent(); inline QString file() const { return f; } - QUrl url() const; + QUrl url() const { return m_url; } bool openFile(QFile &file, QIODevice::OpenMode flags) const; private: QString f; + QUrl m_url; }; #ifndef QT_NO_TOOLBAR @@ -847,7 +849,6 @@ protected: Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE); Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags) -class QScrollPrepareEventPrivate; class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent { public: @@ -865,12 +866,14 @@ public: void setContentPos(const QPointF &pos); private: - QScrollPrepareEventPrivate *d_func(); - const QScrollPrepareEventPrivate *d_func() const; + QObject* m_target; + QPointF m_startPos; + QSizeF m_viewportSize; + QRectF m_contentPosRange; + QPointF m_contentPos; }; -class QScrollEventPrivate; class Q_GUI_EXPORT QScrollEvent : public QEvent { public: @@ -889,11 +892,11 @@ public: ScrollState scrollState() const; private: - QScrollEventPrivate *d_func(); - const QScrollEventPrivate *d_func() const; + QPointF m_contentPos; + QPointF m_overshoot; + QScrollEvent::ScrollState m_state; }; -class QScreenOrientationChangeEventPrivate; class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent { public: @@ -904,8 +907,8 @@ public: Qt::ScreenOrientation orientation() const; private: - QScreenOrientationChangeEventPrivate *d_func(); - const QScreenOrientationChangeEventPrivate *d_func() const; + QScreen *m_screen; + Qt::ScreenOrientation m_orientation; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 18a13b73f5..4bf7dda8d2 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -92,57 +92,6 @@ public: QVector rawScreenPositions; }; -class QFileOpenEventPrivate -{ -public: - inline QFileOpenEventPrivate(const QUrl &url) - : url(url) - { - } - ~QFileOpenEventPrivate(); - - QUrl url; -}; - - -class QScrollPrepareEventPrivate -{ -public: - inline QScrollPrepareEventPrivate() - : target(0) - { - } - - QObject* target; - QPointF startPos; - QSizeF viewportSize; - QRectF contentPosRange; - QPointF contentPos; -}; - -class QScrollEventPrivate -{ -public: - inline QScrollEventPrivate() - { - } - - QPointF contentPos; - QPointF overshoot; - QScrollEvent::ScrollState state; -}; - -class QScreenOrientationChangeEventPrivate -{ -public: - inline QScreenOrientationChangeEventPrivate() - { - } - - QScreen *screen; - Qt::ScreenOrientation orientation; -}; - QT_END_NAMESPACE #endif // QEVENT_P_H -- cgit v1.2.3 From d9a1c2dff85635076ecaee3507427d750846c85c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 2 Apr 2012 13:48:06 +0200 Subject: Logging: Change arguments of message handler to avoid conversions Introduce a new QtMessageHandler that takes QString instead of char *: This avoids converting to local8bit , only to convert it back to utf16 for Windows. The old QMessageHandler is kept for a transition period, but will be removed before Qt 5.0. Also fix qEmergencyOut (that is called in OOM situations) to not rely on the default message handler. Change-Id: Iee0ce5838f97175c98788b847964273dd22d4a37 Reviewed-by: Thiago Macieira --- .../snippets/code/src_corelib_global_qglobal.cpp | 11 +- src/corelib/global/qglobal.cpp | 16 +- src/corelib/global/qlogging.cpp | 163 ++++++++++++++------- src/corelib/global/qlogging.h | 7 +- src/corelib/io/qdebug.h | 2 +- src/corelib/kernel/qcoreapplication_win.cpp | 17 +-- .../auto/corelib/global/qlogging/tst_qlogging.cpp | 10 +- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 28 ++-- 8 files changed, 160 insertions(+), 94 deletions(-) diff --git a/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/src/snippets/code/src_corelib_global_qglobal.cpp index 16f6783a52..dc6c3aa616 100644 --- a/doc/src/snippets/code/src_corelib_global_qglobal.cpp +++ b/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -246,20 +246,21 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2) #include #include -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { + QByteArray localMsg = msg.toLocal8Bit(); switch (type) { case QtDebugMsg: - fprintf(stderr, "Debug: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtWarningMsg: - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); abort(); } } diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 74c65d2504..7036b72f08 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -440,7 +440,7 @@ QT_BEGIN_NAMESPACE Finally, the QtMsgType definition identifies the various messages that can be generated and sent to a Qt message handler; - QMessageHandler is a type definition for a pointer to a function with + QtMessageHandler is a type definition for a pointer to a function with the signature \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}. QMessageLogContext class contains the line, file, and function the @@ -476,7 +476,7 @@ QT_BEGIN_NAMESPACE accept a \l qreal value as their argument returning the value rounded up to the nearest integer and 64-bit integer respectively, the qInstallMessageHandler() function which installs the given - QMessageHandler, and the qVersion() function which returns the + QtMessageHandler, and the qVersion() function which returns the version number of Qt at run-time as a string. \section1 Macros @@ -694,7 +694,7 @@ QT_BEGIN_NAMESPACE \value QtSystemMsg - \sa QMessageHandler, qInstallMessageHandler() + \sa QtMessageHandler, qInstallMessageHandler() */ /*! \typedef QFunctionPointer @@ -3026,12 +3026,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 7 - This typedef is deprecated, you should use QMessageHandler instead. - \sa QtMsgType, QMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() + This typedef is deprecated, you should use QtMessageHandler instead. + \sa QtMsgType, QtMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() */ /*! - \typedef QMessageHandler + \typedef QtMessageHandler \relates \since 5.0 @@ -3044,7 +3044,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) */ /*! - \fn QMessageHandler qInstallMessageHandler(QMessageHandler handler) + \fn QtMessageHandler qInstallMessageHandler(QtMessageHandler handler) \relates \since 5.0 @@ -3074,7 +3074,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 23 - \sa QMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), + \sa QtMessageHandler, QtMsgType, qDebug(), qWarning(), qCritical(), qFatal(), {Debugging Techniques} */ diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index afefb11aa1..1f5b121143 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -49,7 +49,7 @@ #include "qcoreapplication.h" #include "qthread.h" #endif -#ifdef Q_OS_WINCE +#ifdef Q_OS_WIN #include #endif @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE The class provides information about the source code location a qDebug(), qWarning(), qCritical() or qFatal() message was generated. - \sa QMessageLogger, QMessageHandler, qInstallMessageHandler() + \sa QMessageLogger, QtMessageHandler, qInstallMessageHandler() */ /*! @@ -92,6 +92,7 @@ QT_BEGIN_NAMESPACE \internal Uses a local buffer to output the message. Not locale safe + cuts off everything after character 255, but will work in out of memory situations. + Stop the execution afterwards. */ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) { @@ -99,8 +100,33 @@ static void qEmergencyOut(QtMsgType msgType, const char *msg, va_list ap) emergency_buf[255] = '\0'; if (msg) qvsnprintf(emergency_buf, 255, msg, ap); - QMessageLogContext context; - qt_message_output(msgType, context, emergency_buf); + +#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) + OutputDebugStringA(emergency_buf); +#else + fprintf(stderr, "%s", emergency_buf); + fflush(stderr); +#endif + + if (msgType == QtFatalMsg + || (msgType == QtWarningMsg + && (!qgetenv("QT_FATAL_WARNINGS").isNull())) ) { +#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) + // get the current report mode + int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); + _CrtSetReportMode(_CRT_ERROR, reportMode); + int ret = _CrtDbgReport(_CRT_ERROR, __FILE__, __LINE__, QT_VERSION_STR, + msg); + if (ret == 1) + _CrtDbgBreak(); +#endif + +#if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) + abort(); // trap; generates core dump +#else + exit(1); // goodbye cruel world +#endif + } } #endif @@ -116,10 +142,10 @@ static void qt_message(QtMsgType msgType, const QMessageLogContext &context, con return; } #endif - QByteArray buf; + QString buf; if (msg) { QT_TRY { - buf = QString().vsprintf(msg, ap).toLocal8Bit(); + buf = QString().vsprintf(msg, ap); } QT_CATCH(const std::bad_alloc &) { #if !defined(QT_NO_EXCEPTIONS) qEmergencyOut(msgType, msg, ap); @@ -128,7 +154,7 @@ static void qt_message(QtMsgType msgType, const QMessageLogContext &context, con #endif } } - qt_message_output(msgType, context, buf.constData()); + qt_message_output(msgType, context, buf); } #undef qDebug @@ -452,13 +478,13 @@ QMessagePattern::QMessagePattern() else { fprintf(stderr, "%s\n", QString::fromLatin1("QT_MESSAGE_PATTERN: Unknown placeholder %1\n" - ).arg(lexeme).toLocal8Bit().constData()); + ).arg(lexeme).toLatin1().constData()); fflush(stderr); tokens[i] = emptyTokenC; } } else { char *literal = new char[lexeme.size() + 1]; - strncpy(literal, lexeme.toLocal8Bit().constData(), lexeme.size()); + strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); literal[lexeme.size()] = '\0'; literalsVar.append(literal); tokens[i] = literal; @@ -484,16 +510,16 @@ Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) /*! \internal */ -Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, const QMessageLogContext &context, - const char *str) +Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, const QMessageLogContext &context, + const QString &str) { - QByteArray message; + QString message; QMessagePattern *pattern = qMessagePattern(); if (!pattern) { // after destruction of static QMessagePattern instance message.append(str); - message.append('\n'); + message.append(QLatin1Char('\n')); return message; } @@ -503,86 +529,102 @@ Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, const QMessageLogC if (token == messageTokenC) { message.append(str); } else if (token == categoryTokenC) { - message.append(context.category); + message.append(QLatin1String(context.category)); } else if (token == typeTokenC) { switch (type) { - case QtDebugMsg: message.append("debug"); break; - case QtWarningMsg: message.append("warning"); break; - case QtCriticalMsg:message.append("critical"); break; - case QtFatalMsg: message.append("fatal"); break; + case QtDebugMsg: message.append(QLatin1String("debug")); break; + case QtWarningMsg: message.append(QLatin1String("warning")); break; + case QtCriticalMsg:message.append(QLatin1String("critical")); break; + case QtFatalMsg: message.append(QLatin1String("fatal")); break; } } else if (token == fileTokenC) { if (context.file) - message.append(context.file); + message.append(QLatin1String(context.file)); else - message.append("unknown"); + message.append(QLatin1String("unknown")); } else if (token == lineTokenC) { - message.append(QByteArray::number(context.line)); + message.append(QString::number(context.line)); } else if (token == functionTokenC) { if (context.function) - message.append(qCleanupFuncinfo(context.function)); + message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); else - message.append("unknown"); + message.append(QLatin1String("unknown")); #ifndef QT_BOOTSTRAPPED } else if (token == pidTokenC) { - message.append(QByteArray::number(QCoreApplication::applicationPid())); + message.append(QString::number(QCoreApplication::applicationPid())); } else if (token == appnameTokenC) { - message.append(QCoreApplication::applicationName().toUtf8().constData()); + message.append(QCoreApplication::applicationName()); } else if (token == threadidTokenC) { - message.append("0x" + QByteArray::number(qlonglong(QThread::currentThread()->currentThread()), 16)); + message.append(QLatin1String("0x")); + message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); #endif } else { - message.append(token); + message.append(QLatin1String(token)); } } - message.append('\n'); + message.append(QLatin1Char('\n')); return message; } static QtMsgHandler msgHandler = 0; // pointer to debug handler (without context) -static QMessageHandler messageHandler = 0; // pointer to debug handler (with context) +static QtMessageHandler messageHandler = 0; // pointer to debug handler (with context) +static QMessageHandler messageHandler2 = 0; // TODO: Remove before Qt5.0 beta /*! \internal */ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, - const char *buf) + const QString &buf) { - QByteArray logMessage = qMessageFormatString(type, context, buf); + QString logMessage = qMessageFormatString(type, context, buf); #if defined(Q_OS_WINCE) - QString fstr = QString::fromLocal8Bit(logMessage); - OutputDebugString(reinterpret_cast (fstr.utf16())); + OutputDebugString(reinterpret_cast (logMessage.utf16())); #else - fprintf(stderr, "%s", logMessage.constData()); + fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); fflush(stderr); #endif } +/*! + \internal +*/ +static void qDefaultMessageHandler2(QtMsgType type, const QMessageLogContext &context, + const char *buf) +{ + qDefaultMessageHandler(type, context, QString::fromLocal8Bit(buf)); +} + /*! \internal */ static void qDefaultMsgHandler(QtMsgType type, const char *buf) { QMessageLogContext emptyContext; - qDefaultMessageHandler(type, emptyContext, buf); + qDefaultMessageHandler(type, emptyContext, QLatin1String(buf)); } /*! \internal */ -void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const char *buf) +void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message) { if (!msgHandler) msgHandler = qDefaultMsgHandler; if (!messageHandler) messageHandler = qDefaultMessageHandler; + if (!messageHandler2) + messageHandler2 = qDefaultMessageHandler2; + + if (messageHandler == qDefaultMessageHandler + && messageHandler2 != qDefaultMessageHandler2) + (*messageHandler2)(msgType, context, message.toLocal8Bit().constData()); // prefer new message handler over the old one if (msgHandler == qDefaultMsgHandler || messageHandler != qDefaultMessageHandler) { - (*messageHandler)(msgType, context, buf); + (*messageHandler)(msgType, context, message); } else { - (*msgHandler)(msgType, buf); + (*msgHandler)(msgType, message.toLocal8Bit().constData()); } if (msgType == QtFatalMsg @@ -593,14 +635,12 @@ void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, con // get the current report mode int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); _CrtSetReportMode(_CRT_ERROR, reportMode); -#if !defined(Q_OS_WINCE) - int ret = _CrtDbgReport(_CRT_ERROR, context.file, context.line, QT_VERSION_STR, buf); -#else - int ret = _CrtDbgReportW(_CRT_ERROR, _CRT_WIDE(context.file), + + int ret = _CrtDbgReportW(_CRT_ERROR, reinterpret_cast ( + QString::fromLatin1(context.file).utf16()), context.line, _CRT_WIDE(QT_VERSION_STR), reinterpret_cast ( - QString::fromLatin1(buf).utf16())); -#endif + message.utf16())); if (ret == 0 && reportMode & _CRTDBG_MODE_WNDW) return; // ignore else if (ret == 1) @@ -626,8 +666,9 @@ void qErrnoWarning(const char *msg, ...) buf.vsprintf(msg, ap); va_end(ap); - QMessageLogger().critical("%s (%s)", buf.toLocal8Bit().constData(), - qt_error_string(-1).toLocal8Bit().constData()); + buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); + QMessageLogContext context; + qt_message_output(QtCriticalMsg, context, buf); } void qErrnoWarning(int code, const char *msg, ...) @@ -641,22 +682,29 @@ void qErrnoWarning(int code, const char *msg, ...) buf.vsprintf(msg, ap); va_end(ap); - QMessageLogger().critical("%s (%s)", buf.toLocal8Bit().constData(), - qt_error_string(code).toLocal8Bit().constData()); + buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')'); + QMessageLogContext context; + qt_message_output(QtCriticalMsg, context, buf); } #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) extern bool usingWinMain; extern Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str); extern Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, - const char *str); + const QString &str); + +void qWinMessageHandler2(QtMsgType t, const QMessageLogContext &context, + const char *str) +{ + qWinMessageHandler(t, context, QString::fromLocal8Bit(str)); +} #endif -QMessageHandler qInstallMessageHandler(QMessageHandler h) +QtMessageHandler qInstallMessageHandler(QtMessageHandler h) { if (!messageHandler) messageHandler = qDefaultMessageHandler; - QMessageHandler old = messageHandler; + QtMessageHandler old = messageHandler; messageHandler = h; #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) if (!messageHandler && usingWinMain) @@ -665,6 +713,19 @@ QMessageHandler qInstallMessageHandler(QMessageHandler h) return old; } +QMessageHandler qInstallMessageHandler(QMessageHandler h) +{ + if (!messageHandler2) + messageHandler2 = qDefaultMessageHandler2; + QMessageHandler old = messageHandler2; + messageHandler2 = h; +#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) + if (!messageHandler2 && usingWinMain) + messageHandler2 = qWinMessageHandler2; +#endif + return old; +} + QtMsgHandler qInstallMsgHandler(QtMsgHandler h) { //if handler is 0, set it to the diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 29313bd582..216b847952 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -151,7 +151,8 @@ private: # define qWarning QT_NO_QWARNING_MACRO #endif -Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const char *buf); +Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, + const QString &message); Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...); Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...); @@ -160,6 +161,10 @@ Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...); typedef void (*QtMsgHandler)(QtMsgType, const char *); Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler); +typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &); +Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler); + +// TODO: Remove before Qt5.0 Beta typedef void (*QMessageHandler)(QtMsgType, const QMessageLogContext &, const char *); Q_CORE_EXPORT QMessageHandler qInstallMessageHandler(QMessageHandler); diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 48a382eea6..34abb5b75b 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -85,7 +85,7 @@ public: QT_TRY { qt_message_output(stream->type, stream->context, - stream->buffer.toLocal8Bit().data()); + stream->buffer); } QT_CATCH(std::bad_alloc&) { /* We're out of memory - give up. */ } } delete stream; diff --git a/src/corelib/kernel/qcoreapplication_win.cpp b/src/corelib/kernel/qcoreapplication_win.cpp index 7cc1f0e286..5649a8dd76 100644 --- a/src/corelib/kernel/qcoreapplication_win.cpp +++ b/src/corelib/kernel/qcoreapplication_win.cpp @@ -141,29 +141,28 @@ public: }; // defined in qlogging.cpp -extern Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, - const QMessageLogContext &context, - const char *str); +extern Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, + const QMessageLogContext &context, + const QString &str); -Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const char *str) +Q_CORE_EXPORT void qWinMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &str) { // cannot use QMutex here, because qWarning()s in the QMutex // implementation may cause this function to recurse static QWinMsgHandlerCriticalSection staticCriticalSection; - QByteArray message = qMessageFormatString(t, context, str); - QString s(QString::fromLocal8Bit(message)); + QString message = qMessageFormatString(t, context, str); // OutputDebugString is not threadsafe. staticCriticalSection.lock(); - OutputDebugString((wchar_t*)s.utf16()); + OutputDebugString((wchar_t*)message.utf16()); staticCriticalSection.unlock(); } Q_CORE_EXPORT void qWinMsgHandler(QtMsgType t, const char *str) { QMessageLogContext emptyContext; - qWinMessageHandler(t, emptyContext, str); + qWinMessageHandler(t, emptyContext, QString::fromLocal8Bit(str)); } /***************************************************************************** @@ -189,7 +188,7 @@ void qWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, usingWinMain = true; // Install default debug handler - qInstallMsgHandler(qWinMsgHandler); + qInstallMessageHandler(qWinMessageHandler); // Create command line argv = qWinCmdLine(cmdParam, int(strlen(cmdParam)), argc); diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index aaec46fe64..1d6aa89035 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -73,13 +73,13 @@ int s_line; const char *s_function; static QString s_message; -void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const char *msg) +void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { s_type = type; s_file = context.file; s_line = context.line; s_function = context.function; - s_message = QString::fromLocal8Bit(msg); + s_message = msg; } void customMsgHandler(QtMsgType type, const char *msg) @@ -101,7 +101,7 @@ void tst_qmessagehandler::initTestCase() void tst_qmessagehandler::cleanup() { qInstallMsgHandler(0); - qInstallMessageHandler(0); + qInstallMessageHandler((QtMessageHandler)0); s_type = QtFatalMsg; s_file = 0; s_line = 0; @@ -117,7 +117,7 @@ void tst_qmessagehandler::defaultHandler() void tst_qmessagehandler::installMessageHandler() { - QMessageHandler oldHandler = qInstallMessageHandler(customMessageHandler); + QtMessageHandler oldHandler = qInstallMessageHandler(customMessageHandler); qDebug("installMessageHandler"); int line = __LINE__; @@ -127,7 +127,7 @@ void tst_qmessagehandler::installMessageHandler() QCOMPARE(s_function, Q_FUNC_INFO); QCOMPARE(s_line, line); - QMessageHandler myHandler = qInstallMessageHandler(oldHandler); + QtMessageHandler myHandler = qInstallMessageHandler(oldHandler); QCOMPARE((void*)myHandler, (void*)customMessageHandler); } diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 12f7e28a1d..035c781e4a 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -74,12 +74,12 @@ void tst_QDebug::assignment() const } static QtMsgType s_msgType; -static QByteArray s_msg; +static QString s_msg; static QByteArray s_file; static int s_line; static QByteArray s_function; -static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const char *msg) +static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { s_msg = msg; s_msgType = type; @@ -94,7 +94,7 @@ static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, class MessageHandlerSetter { public: - MessageHandlerSetter(QMessageHandler newMessageHandler) + MessageHandlerSetter(QtMessageHandler newMessageHandler) : oldMessageHandler(qInstallMessageHandler(newMessageHandler)) { } @@ -104,7 +104,7 @@ public: } private: - QMessageHandler oldMessageHandler; + QtMessageHandler oldMessageHandler; }; /*! \internal @@ -116,7 +116,7 @@ void tst_QDebug::warningWithoutDebug() const { qWarning() << "A qWarning() message"; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtWarningMsg); - QCOMPARE(QString::fromLatin1(s_msg.data()), QString::fromLatin1("A qWarning() message ")); + QCOMPARE(s_msg, QString::fromLatin1("A qWarning() message ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -131,7 +131,7 @@ void tst_QDebug::criticalWithoutDebug() const { qCritical() << "A qCritical() message"; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtCriticalMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("A qCritical() message ")); + QCOMPARE(s_msg, QString::fromLatin1("A qCritical() message ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -143,7 +143,7 @@ void tst_QDebug::debugWithBool() const { qDebug() << false << true; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("false true ")); + QCOMPARE(s_msg, QString::fromLatin1("false true ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -161,7 +161,7 @@ void tst_QDebug::veryLongWarningMessage() const } QString file = __FILE__; int line = __LINE__ - 2; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtWarningMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("Test output:\n")+test+QString::fromLatin1("\nend")); + QCOMPARE(s_msg, QString::fromLatin1("Test output:\n")+test+QString::fromLatin1("\nend")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -178,7 +178,7 @@ void tst_QDebug::qDebugQStringRef() const { qDebug() << inRef; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"input\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"input\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -192,7 +192,7 @@ void tst_QDebug::qDebugQStringRef() const { qDebug() << inRef; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -205,7 +205,7 @@ void tst_QDebug::qDebugQLatin1String() const { qDebug() << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"foo\" \"\" \"bar\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -214,11 +214,11 @@ void tst_QDebug::qDebugQLatin1String() const void tst_QDebug::defaultMessagehandler() const { MessageHandlerSetter mhs(0); - QMessageHandler defaultMessageHandler1 = qInstallMessageHandler(0); - QMessageHandler defaultMessageHandler2 = qInstallMessageHandler(myMessageHandler); + QtMessageHandler defaultMessageHandler1 = qInstallMessageHandler((QtMessageHandler)0); + QtMessageHandler defaultMessageHandler2 = qInstallMessageHandler(myMessageHandler); bool same = (*defaultMessageHandler1 == *defaultMessageHandler2); QVERIFY(same); - QMessageHandler messageHandler = qInstallMessageHandler(0); + QtMessageHandler messageHandler = qInstallMessageHandler((QtMessageHandler)0); same = (*messageHandler == *myMessageHandler); QVERIFY(same); } -- cgit v1.2.3 From 80ad5938ea20f1dc91636cee10ca04bba94929e8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 Apr 2012 21:24:22 +0200 Subject: Stop using QEventPrivate::d in QWindowStateChangeEvent We can add a boolean and avoid using the d pointer (which QEvent now checks to be unused). Change-Id: I7367d5410d10ed06441fe9037cac0e3473d62498 Reviewed-by: Olivier Goffart --- src/gui/kernel/qevent.cpp | 13 ++----------- src/gui/kernel/qevent.h | 4 ++-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 7f1a850cda..52880a231d 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3277,27 +3277,18 @@ QClipboardEvent::~QClipboardEvent() Returns the state of the window before the change. */ -/*! \internal - */ -QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s) - : QEvent(WindowStateChange), ostate(s) -{ -} - /*! \internal */ QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates s, bool isOverride) - : QEvent(WindowStateChange), ostate(s) + : QEvent(WindowStateChange), ostate(s), m_override(isOverride) { - if (isOverride) - d = (QEventPrivate*)(this); } /*! \internal */ bool QWindowStateChangeEvent::isOverride() const { - return (d != 0); + return m_override; } /*! \internal diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index de4befb64c..176747aa95 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -698,8 +698,7 @@ public: class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent { public: - explicit QWindowStateChangeEvent(Qt::WindowStates aOldState); - QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride); + explicit QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride = false); ~QWindowStateChangeEvent(); inline Qt::WindowStates oldState() const { return ostate; } @@ -707,6 +706,7 @@ public: private: Qt::WindowStates ostate; + bool m_override; }; #ifndef QT_NO_DEBUG_STREAM -- cgit v1.2.3 From 33371c016e13dadcf7535e11e38065ab193b2c6e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 3 Apr 2012 18:26:27 -0300 Subject: Add unit testing for the qdbusxml2cpp tool I have not added tests for warnings or other failure to input. This tests only proper output for the moment. Change-Id: Ie01fd2a78adfa57c27bf288a08cd44ae82f51241 Reviewed-by: Jason McDonald --- tests/auto/tools/qdbusxml2cpp/qdbusxml2cpp.pro | 5 + tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp | 263 +++++++++++++++++++++ tests/auto/tools/tools.pro | 2 +- 3 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 tests/auto/tools/qdbusxml2cpp/qdbusxml2cpp.pro create mode 100644 tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp diff --git a/tests/auto/tools/qdbusxml2cpp/qdbusxml2cpp.pro b/tests/auto/tools/qdbusxml2cpp/qdbusxml2cpp.pro new file mode 100644 index 0000000000..8c29ff47c4 --- /dev/null +++ b/tests/auto/tools/qdbusxml2cpp/qdbusxml2cpp.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +QT = core testlib +TARGET = tst_qdbusxml2cpp +SOURCES += tst_qdbusxml2cpp.cpp +QMAKE_CXXFLAGS += $$QT_CFLAGS_DBUS diff --git a/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp new file mode 100644 index 0000000000..aaa2bb4235 --- /dev/null +++ b/tests/auto/tools/qdbusxml2cpp/tst_qdbusxml2cpp.cpp @@ -0,0 +1,263 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Intel Corporation. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +class tst_qdbusxml2cpp : public QObject +{ + Q_OBJECT + + enum { Interface, Adaptor }; + +private slots: + void initTestCase_data(); + void process_data(); + void process(); +}; + +struct BasicTypeList { + char dbusType[3]; + char cppType[24]; +}; +static const BasicTypeList basicTypeList[] = +{ + { DBUS_TYPE_BOOLEAN_AS_STRING, "bool" }, + { DBUS_TYPE_BYTE_AS_STRING, "uchar" }, + { DBUS_TYPE_INT16_AS_STRING, "short" }, + { DBUS_TYPE_UINT16_AS_STRING, "ushort" }, + { DBUS_TYPE_INT32_AS_STRING, "int" }, + { DBUS_TYPE_UINT32_AS_STRING, "uint" }, + { DBUS_TYPE_INT64_AS_STRING, "qlonglong" }, + { DBUS_TYPE_UINT64_AS_STRING, "qulonglong" }, + { DBUS_TYPE_DOUBLE_AS_STRING, "double" }, + { DBUS_TYPE_STRING_AS_STRING, "QString" }, + { DBUS_TYPE_OBJECT_PATH_AS_STRING, "QDBusObjectPath" }, + { DBUS_TYPE_SIGNATURE_AS_STRING, "QDBusSignature" }, +#ifdef DBUS_TYPE_UNIX_FD_AS_STRING + { DBUS_TYPE_UNIX_FD_AS_STRING, "QDBusUnixFileDescriptor" }, +#endif + { DBUS_TYPE_VARIANT_AS_STRING, "QDBusVariant" }, + { DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING, "QByteArray" }, + { DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, "QStringList" }, + { DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_VARIANT_AS_STRING, "QVariantList" } +}; +static const int basicTypeCount = sizeof(basicTypeList) / sizeof(basicTypeList[0]); + +static QString stripHeader(QString output) +{ + static QRegularExpression header("^.*?(?=\\Rclass)", QRegularExpression::DotMatchesEverythingOption); + return output.remove(header); +} + +void tst_qdbusxml2cpp::initTestCase_data() +{ + QTest::addColumn("outputMode"); + QTest::addColumn("commandLineArg"); + QTest::newRow("interface") << int(Interface) << "-p"; + QTest::newRow("adaptor") << int(Adaptor) << "-a"; +} + +void tst_qdbusxml2cpp::process_data() +{ + QTest::addColumn("xmlSnippet"); + QTest::addColumn("interfaceSearch"); + QTest::addColumn("adaptorSearch"); + + // -- class info -- + QTest::newRow("classinfo") + << "" + << QRegularExpression("staticInterfaceName\\(\\)\\s+" + "{ return \"local\\.name\\.is\\.not\\.important\"\\; }") + << QRegularExpression("Q_CLASSINFO\\(\"D-Bus Interface\", \"local\\.name\\.is\\.not\\.important\"\\)"); + + // -- properties -- + for (int i = 0; i < basicTypeCount; ++i) { + QRegularExpression rx(QString("\\bQ_PROPERTY\\(%1 PropertyIsPresent " + "READ propertyIsPresent WRITE setPropertyIsPresent\\b") + .arg(basicTypeList[i].cppType)); + QTest::newRow(QByteArray("property-") + basicTypeList[i].dbusType) + << QString("") + .arg(basicTypeList[i].dbusType) + << rx << rx; + } + + QTest::newRow("property-readonly-multi") + << "" + << QRegularExpression("\\bQ_PROPERTY\\(int Value READ value(?! WRITE)") + << QRegularExpression("\\bQ_PROPERTY\\(int Value READ value(?! WRITE)"); + QTest::newRow("property-readonly") + << "" + << QRegularExpression("\\bQ_PROPERTY\\(int Value READ value(?! WRITE)") + << QRegularExpression("\\bQ_PROPERTY\\(int Value READ value(?! WRITE)"); + QTest::newRow("property-writeonly") + << "" + << QRegularExpression("\\bQ_PROPERTY\\(int Value WRITE setValue\\b") + << QRegularExpression("\\bQ_PROPERTY\\(int Value WRITE setValue\\b"); + + QTest::newRow("property-getter-setter") + << "" + "" + "" + "" + << QRegularExpression("\\bQ_PROPERTY\\(bool Enabled READ wasEnabled WRITE setEnabledFlag\\b.*" + "\\bbool wasEnabled\\(\\) const.*" // no semi-colon + "\\bvoid setEnabledFlag\\(bool", QRegularExpression::DotMatchesEverythingOption) + << QRegularExpression("\\bQ_PROPERTY\\(bool Enabled READ wasEnabled WRITE setEnabledFlag\\b.*" + "\\bbool wasEnabled\\(\\) const;.*" // has semi-colon + "\\bvoid setEnabledFlag\\(bool", QRegularExpression::DotMatchesEverythingOption); + + QTest::newRow("property-complex") + << "" + "" + "" + << QRegularExpression("\\bQ_PROPERTY\\(Point Position READ position WRITE setPosition\\b") + << QRegularExpression("\\bQ_PROPERTY\\(Point Position READ position WRITE setPosition\\b"); + + // -- methods -- + for (int i = 0; i < basicTypeCount; ++i) { + QTest::newRow(QByteArray("method-") + basicTypeList[i].dbusType) + << QString("" + "" + "" + "") + .arg(basicTypeList[i].dbusType) + << QRegularExpression(QString("Q_SLOTS:.*\\bQDBusPendingReply<%1> Method\\((const )?%1 ") + .arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption) + << QRegularExpression(QString("Q_SLOTS:.*\\b%1 Method\\((const )?%1 ") + .arg(basicTypeList[i].cppType), QRegularExpression::DotMatchesEverythingOption); + } + + QTest::newRow("method-complex") + << "" + "" + "" + "" + "" + "" + << QRegularExpression("Q_SLOTS:.*\\bQDBusPendingReply Method\\(PointF ", + QRegularExpression::DotMatchesEverythingOption) + << QRegularExpression("Q_SLOTS:.*\\bPoint Method\\(PointF ", + QRegularExpression::DotMatchesEverythingOption); + + QTest::newRow("method-ss") + << "" + "" + "" + "" + "" + "" + << QRegularExpression("Q_SLOTS:.*QDBusPendingReply Method\\(const QString &\\w*, const QString &", + QRegularExpression::DotMatchesEverythingOption) + << QRegularExpression("Q_SLOTS:.*QString Method\\(const QString &\\w*, const QString &\\w*, QString &", + QRegularExpression::DotMatchesEverythingOption); + + // -- signals -- + for (int i = 0; i < basicTypeCount; ++i) { + QRegularExpression rx(QString("Q_SIGNALS:.*\\bvoid Signal\\((const )?%1\\b") + .arg(basicTypeList[i].cppType), + QRegularExpression::DotMatchesEverythingOption); + QTest::newRow(QByteArray("signal-") + basicTypeList[i].dbusType) + << QString("" + "" + "") + .arg(basicTypeList[i].dbusType) + << rx << rx; + } +} + +void tst_qdbusxml2cpp::process() +{ + QFETCH(QString, xmlSnippet); + QFETCH(QRegularExpression, interfaceSearch); + QFETCH(QRegularExpression, adaptorSearch); + QVERIFY2(interfaceSearch.isValid(), qPrintable(interfaceSearch.errorString())); + QVERIFY2(adaptorSearch.isValid(), qPrintable(adaptorSearch.errorString())); + + // test both interface and adaptor generation + QFETCH_GLOBAL(int, outputMode); + QFETCH_GLOBAL(QString, commandLineArg); + + // Run the tool + QProcess process; + process.start("qdbusxml2cpp", QStringList() << commandLineArg << "-" << "-N"); + QVERIFY2(process.waitForStarted(), qPrintable(process.errorString())); + + // feed it our XML data + static const char xmlHeader[] = + "\n" + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE // \n is included + "\n" + " \n" + " \n"; + static const char xmlFooter[] = "\n" + " \n" + " \n" + "\n"; + + process.write(xmlHeader, int(sizeof xmlHeader) - 1); + process.write(xmlSnippet.toLatin1()); + process.write(xmlFooter, int(sizeof xmlFooter) - 1); + while (process.bytesToWrite()) + QVERIFY2(process.waitForBytesWritten(), qPrintable(process.errorString())); + // fprintf(stderr, "%s%s%s", xmlHeader, xmlSnippet.toLatin1().constData(), xmlFooter); + + process.closeWriteChannel(); + QVERIFY2(process.waitForFinished(), qPrintable(process.errorString())); + + QByteArray errOutput = process.readAllStandardError(); + QVERIFY2(errOutput.isEmpty(), errOutput); + QCOMPARE(process.exitCode(), 0); + + QByteArray fullOutput = process.readAll(); + QString output = stripHeader(QString::fromLatin1(fullOutput)); + QVERIFY2(!output.isEmpty(), fullOutput); + if (outputMode == Interface) + QVERIFY2(output.count(interfaceSearch) == 1, qPrintable(interfaceSearch.pattern() + "\nin\n" + output)); + else + QVERIFY2(output.count(adaptorSearch) == 1, qPrintable(adaptorSearch.pattern() + "\nin\n" + output)); +} + +QTEST_MAIN(tst_qdbusxml2cpp) + +#include "tst_qdbusxml2cpp.moc" diff --git a/tests/auto/tools/tools.pro b/tests/auto/tools/tools.pro index 0a2821773f..4cc3d62a43 100644 --- a/tests/auto/tools/tools.pro +++ b/tests/auto/tools/tools.pro @@ -5,4 +5,4 @@ SUBDIRS=\ moc \ rcc \ -contains(QT_CONFIG, dbus):SUBDIRS += qdbuscpp2xml +contains(QT_CONFIG, dbus):SUBDIRS += qdbuscpp2xml qdbusxml2cpp -- cgit v1.2.3 From d631c31235dc3ab682ba5d4cbb466680d47b36f2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 20 Oct 2011 12:47:04 +0200 Subject: Make QStringLiteral and QByteArrayLiteral always return the real types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Up until now, the macros would return an internal type that contained the pointer to the data. This breaks code that tried to use the macros with operators, like QStringBuilder but also when writing: QStringList() << QStringLiteral("a") << QStringLiteral("b"); This change seems to work fine now and I can also verify that this works: const auto str = QStringLiteral("Hello"); Even though it creates a QString, which is non-POD and non-constexpr. Change-Id: Iaf82af9bea4245513a1128ea54f9d2d3d785fb09 Reviewed-by: Olivier Goffart Reviewed-by: Jędrzej Nowacki --- src/corelib/tools/qbytearray.h | 13 ++++----- src/corelib/tools/qstring.h | 14 +++++----- src/corelib/tools/qstringbuilder.h | 31 ---------------------- .../qstringbuilder1/stringbuilder.cpp | 30 --------------------- 4 files changed, 15 insertions(+), 73 deletions(-) diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 45be63aa9b..0f5ebcfb18 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -169,13 +169,14 @@ struct QByteArrayDataPtr #if defined(Q_COMPILER_LAMBDA) # define QByteArrayLiteral(str) \ - ([]() -> QByteArrayDataPtr { \ + ([]() -> QByteArray { \ enum { Size = sizeof(str) - 1 }; \ static const QStaticByteArrayData qbytearray_literal = { \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ - return holder; \ + const QByteArray ba(holder); \ + return ba; \ }()) \ /**/ @@ -185,22 +186,22 @@ struct QByteArrayDataPtr // To do that, we need the __extension__ {( )} trick which only GCC supports # define QByteArrayLiteral(str) \ - __extension__ ({ \ + QByteArray(__extension__ ({ \ enum { Size = sizeof(str) - 1 }; \ static const QStaticByteArrayData qbytearray_literal = { \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(Size), \ str }; \ QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; \ holder; \ - }) \ + })) \ /**/ #endif #ifndef QByteArrayLiteral -// no lambdas, not GCC, use const char * instead +// no lambdas, not GCC, just return a temporary QByteArray -# define QByteArrayLiteral(str) (str) +# define QByteArrayLiteral(str) QByteArray(str, sizeof(str) - 1) #endif class Q_CORE_EXPORT QByteArray diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index edb140b682..a96046d837 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -113,13 +113,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, # if defined(Q_COMPILER_LAMBDA) # define QStringLiteral(str) \ - ([]() -> QStringDataPtr { \ + ([]() -> QString { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ - return holder; \ + const QString s(holder); \ + return s; \ }()) \ /**/ @@ -129,14 +130,14 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, // To do that, we need the __extension__ {( )} trick which only GCC supports # define QStringLiteral(str) \ - __extension__ ({ \ + QString(__extension__ ({ \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ static const QStaticStringData qstring_literal = { \ Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ QT_UNICODE_LITERAL(str) }; \ QStringDataPtr holder = { qstring_literal.data_ptr() }; \ holder; \ - }) \ + })) \ /**/ # endif @@ -144,9 +145,10 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, #ifndef QStringLiteral // no lambdas, not GCC, or GCC in C++98 mode with 4-byte wchar_t -// fallback, uses QLatin1String as next best options +// fallback, return a temporary QString +// source code is assumed to be encoded in UTF-8 -# define QStringLiteral(str) QLatin1String(str) +# define QStringLiteral(str) QString::fromUtf8(str, sizeof(str) - 1) #endif #define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index 9a1fd6949b..9b1cd1ee7e 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -253,19 +253,6 @@ template <> struct QConcatenable : private QAbstractConcatenable } }; -template <> struct QConcatenable : private QAbstractConcatenable -{ - typedef QStringDataPtr type; - typedef QString ConvertTo; - enum { ExactSize = true }; - static int size(const type &a) { return a.ptr->size; } - static inline void appendTo(const type &a, QChar *&out) - { - memcpy(out, reinterpret_cast(a.ptr->data()), sizeof(QChar) * a.ptr->size); - out += a.ptr->size; - } -}; - template <> struct QConcatenable : private QAbstractConcatenable { typedef QStringRef type; @@ -358,24 +345,6 @@ template <> struct QConcatenable : private QAbstractConcatenable } }; -template <> struct QConcatenable : private QAbstractConcatenable -{ - typedef QByteArrayDataPtr type; - typedef QByteArray ConvertTo; - enum { ExactSize = false }; - static int size(const type &ba) { return ba.ptr->size; } -#ifndef QT_NO_CAST_FROM_ASCII - static inline QT_ASCII_CAST_WARN void appendTo(const type &a, QChar *&out) - { - QAbstractConcatenable::convertFromAscii(a.ptr->data(), a.ptr->size, out); - } -#endif - static inline void appendTo(const type &ba, char *&out) - { - ::memcpy(out, ba.ptr->data(), ba.ptr->size); - out += ba.ptr->size; - } -}; template struct QConcatenable< QStringBuilder > diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp index 862789cc73..556b9ac16a 100644 --- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp +++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp @@ -107,21 +107,6 @@ void runScenario() QCOMPARE(r, r3); #endif - { - static const QStaticStringData<12> literalData = { - Q_STATIC_STRING_DATA_HEADER_INITIALIZER(12), - { 's', 'o', 'm', 'e', ' ', 'l', 'i', 't', 'e', 'r', 'a', 'l' } - }; - static QStringDataPtr literal = { literalData.data_ptr() }; - - r = literal; - QCOMPARE(r, string); - r = r Q literal; - QCOMPARE(r, r2); - r = literal Q literal; - QCOMPARE(r, r2); - } - #ifndef QT_NO_CAST_FROM_ASCII r = string P LITERAL; QCOMPARE(r, r2); @@ -226,21 +211,6 @@ void runScenario() QCOMPARE(r, ba); } - { - static const QStaticByteArrayData<12> literalData = { - Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(12), - { 's', 'o', 'm', 'e', ' ', 'l', 'i', 't', 'e', 'r', 'a', 'l' } - }; - static QByteArrayDataPtr literal = { literalData.data_ptr() }; - - QByteArray ba = literal; - QCOMPARE(ba, QByteArray(LITERAL)); - ba = ba Q literal; - QCOMPARE(ba, QByteArray(LITERAL LITERAL)); - ba = literal Q literal; - QCOMPARE(ba, QByteArray(LITERAL LITERAL)); - } - //operator QString += { QString str = QString::fromUtf8(UTF8_LITERAL); -- cgit v1.2.3 From f02e1d6d8e0ee560667b445e8fa43bde85e31f41 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 Apr 2012 21:16:47 +0200 Subject: Move QGestureEventPrivate's content to the main class QEvent now checks that the d pointer is unused. Change-Id: Ib0aa97d1692ea55324c4c6f133ffdd5a221f1680 Reviewed-by: Lars Knoll --- src/widgets/kernel/qapplication.cpp | 4 ++-- src/widgets/kernel/qgesture.cpp | 42 ++++++++++------------------------ src/widgets/kernel/qgesture.h | 6 +++-- src/widgets/kernel/qgesture_p.h | 13 ----------- src/widgets/kernel/qgesturemanager.cpp | 4 ++-- 5 files changed, 20 insertions(+), 49 deletions(-) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index ee4f9bd6bb..f672aef0eb 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3523,7 +3523,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) ge.t = gestureEvent->t; ge.spont = gestureEvent->spont; ge.m_accept = wasAccepted; - ge.d_func()->accepted = gestureEvent->d_func()->accepted; + ge.m_accepted = gestureEvent->m_accepted; res = d->notify_helper(w, &ge); gestureEvent->spont = false; eventAccepted = ge.isAccepted(); @@ -3533,7 +3533,7 @@ bool QApplication::notify(QObject *receiver, QEvent *e) // packed into a single QEvent depends on not consuming the event if (eventAccepted || ge.isAccepted(g)) { // if the gesture was accepted, mark the target widget for it - gestureEvent->d_func()->targetWidgets[g->gestureType()] = w; + gestureEvent->m_targetWidgets[g->gestureType()] = w; gestureEvent->setAccepted(g, true); } else { // if the gesture was explicitly ignored by the application, diff --git a/src/widgets/kernel/qgesture.cpp b/src/widgets/kernel/qgesture.cpp index 070af65c70..4f899e5644 100644 --- a/src/widgets/kernel/qgesture.cpp +++ b/src/widgets/kernel/qgesture.cpp @@ -846,9 +846,9 @@ int QTapAndHoldGesturePrivate::Timeout = 700; // in ms Creates new QGestureEvent containing a list of \a gestures. */ QGestureEvent::QGestureEvent(const QList &gestures) - : QEvent(QEvent::Gesture) + : QEvent(QEvent::Gesture), m_gestures(gestures), m_widget(0) + { - d = reinterpret_cast(new QGestureEventPrivate(gestures)); } /*! @@ -856,7 +856,6 @@ QGestureEvent::QGestureEvent(const QList &gestures) */ QGestureEvent::~QGestureEvent() { - delete reinterpret_cast(d); } /*! @@ -864,7 +863,7 @@ QGestureEvent::~QGestureEvent() */ QList QGestureEvent::gestures() const { - return d_func()->gestures; + return m_gestures; } /*! @@ -872,10 +871,9 @@ QList QGestureEvent::gestures() const */ QGesture *QGestureEvent::gesture(Qt::GestureType type) const { - const QGestureEventPrivate *d = d_func(); - for(int i = 0; i < d->gestures.size(); ++i) - if (d->gestures.at(i)->gestureType() == type) - return d->gestures.at(i); + for (int i = 0; i < m_gestures.size(); ++i) + if (m_gestures.at(i)->gestureType() == type) + return m_gestures.at(i); return 0; } @@ -885,7 +883,7 @@ QGesture *QGestureEvent::gesture(Qt::GestureType type) const QList QGestureEvent::activeGestures() const { QList gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() != Qt::GestureCanceled) gestures.append(gesture); } @@ -898,7 +896,7 @@ QList QGestureEvent::activeGestures() const QList QGestureEvent::canceledGestures() const { QList gestures; - foreach (QGesture *gesture, d_func()->gestures) { + foreach (QGesture *gesture, m_gestures) { if (gesture->state() == Qt::GestureCanceled) gestures.append(gesture); } @@ -980,7 +978,7 @@ bool QGestureEvent::isAccepted(QGesture *gesture) const void QGestureEvent::setAccepted(Qt::GestureType gestureType, bool value) { setAccepted(false); - d_func()->accepted[gestureType] = value; + m_accepted[gestureType] = value; } /*! @@ -1017,7 +1015,7 @@ void QGestureEvent::ignore(Qt::GestureType gestureType) */ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const { - return d_func()->accepted.value(gestureType, true); + return m_accepted.value(gestureType, true); } /*! @@ -1027,7 +1025,7 @@ bool QGestureEvent::isAccepted(Qt::GestureType gestureType) const */ void QGestureEvent::setWidget(QWidget *widget) { - d_func()->widget = widget; + m_widget = widget; } /*! @@ -1035,7 +1033,7 @@ void QGestureEvent::setWidget(QWidget *widget) */ QWidget *QGestureEvent::widget() const { - return d_func()->widget; + return m_widget; } #ifndef QT_NO_GRAPHICSVIEW @@ -1062,22 +1060,6 @@ QPointF QGestureEvent::mapToGraphicsScene(const QPointF &gesturePoint) const } #endif //QT_NO_GRAPHICSVIEW -/*! - \internal -*/ -QGestureEventPrivate *QGestureEvent::d_func() -{ - return reinterpret_cast(d); -} - -/*! - \internal -*/ -const QGestureEventPrivate *QGestureEvent::d_func() const -{ - return reinterpret_cast(d); -} - #ifdef Q_NO_USING_KEYWORD /*! \fn void QGestureEvent::setAccepted(bool accepted) diff --git a/src/widgets/kernel/qgesture.h b/src/widgets/kernel/qgesture.h index 5e121def41..ec5048089d 100644 --- a/src/widgets/kernel/qgesture.h +++ b/src/widgets/kernel/qgesture.h @@ -310,8 +310,10 @@ public: #endif private: - QGestureEventPrivate *d_func(); - const QGestureEventPrivate *d_func() const; + QList m_gestures; + QWidget *m_widget; + QMap m_accepted; + QMap m_targetWidgets; friend class QApplication; friend class QGestureManager; diff --git a/src/widgets/kernel/qgesture_p.h b/src/widgets/kernel/qgesture_p.h index ceccf17a6c..85793f6f7f 100644 --- a/src/widgets/kernel/qgesture_p.h +++ b/src/widgets/kernel/qgesture_p.h @@ -222,19 +222,6 @@ public: #endif }; -class QGestureEventPrivate -{ -public: - inline QGestureEventPrivate(const QList &list) - : gestures(list), widget(0) - { - } - - QList gestures; - QWidget *widget; - QMap accepted; - QMap targetWidgets; -}; #endif // QT_NO_GESTURES diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index f4bf667ef8..8ba8904684 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -660,7 +660,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, bool eventAccepted = event.isAccepted(); foreach(QGesture *gesture, event.gestures()) { if (eventAccepted || event.isAccepted(gesture)) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "override event: gesture was accepted:" << gesture << w; QList &gestures = normalStartedGestures[w]; @@ -687,7 +687,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, foreach (QGesture *gesture, event.gestures()) { if (gesture->state() == Qt::GestureStarted && (eventAccepted || event.isAccepted(gesture))) { - QWidget *w = event.d_func()->targetWidgets.value(gesture->gestureType(), 0); + QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); Q_ASSERT(w); DEBUG() << "started gesture was delivered and accepted by" << w; m_gestureTargets[gesture] = w; -- cgit v1.2.3 From e92e5fda44602d7595aca329a3133ecb9991a6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Sun, 1 Apr 2012 01:18:27 +0200 Subject: Migrate QString over to QArrayData MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ieadc60523a2bef61a088920576c65c720b11bfb9 Reviewed-by: Jędrzej Nowacki Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 85 ++++++++++++------------------------------- src/corelib/tools/qstring.h | 29 ++++----------- 2 files changed, 32 insertions(+), 82 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a536a091a1..ed0c493c7a 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -796,9 +796,6 @@ const QString::Null QString::null = { }; \sa split() */ -const QStaticStringData<1> QString::shared_null = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; -const QStaticStringData<1> QString::shared_empty = { Q_STATIC_STRING_DATA_HEADER_INITIALIZER(0), { 0 } }; - /*! \typedef QString::ConstIterator Qt-style synonym for QString::const_iterator. @@ -1039,7 +1036,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) QString::QString(const QChar *unicode, int size) { if (!unicode) { - d = shared_null.data_ptr(); + d = Data::sharedNull(); } else { if (size < 0) { size = 0; @@ -1047,15 +1044,11 @@ QString::QString(const QChar *unicode, int size) ++size; } if (!size) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); memcpy(d->data(), unicode, size * sizeof(QChar)); d->data()[size] = '\0'; } @@ -1071,15 +1064,11 @@ QString::QString(const QChar *unicode, int size) QString::QString(int size, QChar ch) { if (size <= 0) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; ushort *i = d->data() + size; ushort *b = d->data(); @@ -1097,13 +1086,9 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; } @@ -1119,13 +1104,9 @@ QString::QString(int size, Qt::Initialization) */ QString::QString(QChar ch) { - d = (Data *) ::malloc(sizeof(Data) + 2*sizeof(QChar)); + d = Data::allocate(2); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = 1; - d->alloc = 2u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[0] = ch.unicode(); d->data()[1] = '\0'; } @@ -1182,12 +1163,6 @@ QString::QString(QChar ch) \internal */ -// ### Qt 5: rename freeData() to avoid confusion. See task 197625. -void QString::free(Data *d) -{ - ::free(d); -} - /*! Sets the size of the string to \a size characters. @@ -1229,9 +1204,9 @@ void QString::resize(int size) } if (size == 0 && !d->capacityReserved) { - Data *x = shared_empty.data_ptr(); + Data *x = Data::allocate(0); if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = x; } else { if (d->ref.isShared() || uint(size) + 1u > d->alloc @@ -1301,17 +1276,14 @@ void QString::reallocData(uint alloc, bool grow) alloc = qAllocMore(alloc * sizeof(QChar), sizeof(Data)) / sizeof(QChar); if (d->ref.isShared() || IS_RAW_DATA(d)) { - Data *x = static_cast(::malloc(sizeof(Data) + alloc * sizeof(QChar))); + Data::AllocationOptions allocOptions(d->capacityReserved ? Data::CapacityReserved : 0); + Data *x = Data::allocate(alloc, allocOptions); Q_CHECK_PTR(x); - x->ref.initializeOwned(); x->size = qMin(int(alloc) - 1, d->size); - x->alloc = alloc; - x->capacityReserved = d->capacityReserved; - x->offset = sizeof(QStringData); ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); x->data()[x->size] = 0; if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = x; } else { Data *p = static_cast(::realloc(d, sizeof(Data) + alloc * sizeof(QChar))); @@ -1351,7 +1323,7 @@ QString &QString::operator=(const QString &other) { other.d->ref.ref(); if (!d->ref.deref()) - QString::free(d); + Data::deallocate(d); d = other.d; return *this; } @@ -1521,8 +1493,8 @@ QString& QString::insert(int i, QChar ch) */ QString &QString::append(const QString &str) { - if (str.d != &shared_null.str) { - if (d == &shared_null.str) { + if (str.d != Data::sharedNull()) { + if (d == Data::sharedNull()) { operator=(str); } else { if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc) @@ -4051,19 +4023,15 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) { Data *d; if (!str) { - d = shared_null.data_ptr(); + d = Data::sharedNull(); } else if (size == 0 || (!*str && size < 0)) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { if (size < 0) size = qstrlen(str); - d = static_cast(::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar))); + d = Data::allocate(size + 1); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = uint(size) + 1u; - d->capacityReserved = false; - d->offset = sizeof(QStringData); d->data()[size] = '\0'; ushort *dst = d->data(); /* SIMD: @@ -4129,7 +4097,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) if (!str) return QString(); if (size == 0 || (!*str && size < 0)) { - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } #if !defined(QT_NO_TEXTCODEC) @@ -4298,7 +4266,7 @@ QString QString::simplified() const break; if (++from == fromEnd) { // All-whitespace string - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } } @@ -4393,7 +4361,7 @@ QString QString::trimmed() const } int l = end - start + 1; if (l <= 0) { - QStringDataPtr empty = { shared_empty.data_ptr() }; + QStringDataPtr empty = { Data::allocate(0) }; return QString(empty); } return QString(s + start, l); @@ -7413,17 +7381,12 @@ QString QString::fromRawData(const QChar *unicode, int size) { Data *x; if (!unicode) { - x = shared_null.data_ptr(); + x = Data::sharedNull(); } else if (!size) { - x = shared_empty.data_ptr(); + x = Data::allocate(0); } else { - x = static_cast(::malloc(sizeof(Data))); + x = Data::fromRawData(reinterpret_cast(unicode), size); Q_CHECK_PTR(x); - x->ref.initializeOwned(); - x->size = size; - x->alloc = 0; - x->capacityReserved = false; - x->offset = reinterpret_cast(unicode) - reinterpret_cast(x); } QStringDataPtr dataPtr = { x }; return QString(dataPtr); diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a96046d837..9fcd203a3f 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -69,17 +69,7 @@ class QLatin1String; class QStringRef; template class QVector; -struct QStringData { - QtPrivate::RefCount ref; - int size; - uint alloc : 31; - uint capacityReserved : 1; - - qptrdiff offset; - - inline ushort *data() { return reinterpret_cast(reinterpret_cast(this) + offset); } - inline const ushort *data() const { return reinterpret_cast(reinterpret_cast(this) + offset); } -}; +typedef QTypedArrayData QStringData; #if defined(Q_COMPILER_UNICODE_STRINGS) @@ -162,13 +152,13 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, template struct QStaticStringData { - QStringData str; + QArrayData str; qunicodechar data[N + 1]; QStringData *data_ptr() const { Q_ASSERT(str.ref.isStatic()); - return const_cast(&str); + return const_cast(static_cast(&str)); } }; @@ -621,9 +611,9 @@ public: // compatibility struct Null { }; static const Null null; - inline QString(const Null &): d(shared_null.data_ptr()) {} + inline QString(const Null &): d(Data::sharedNull()) {} inline QString &operator=(const Null &) { *this = QString(); return *this; } - inline bool isNull() const { return d == &shared_null.str; } + inline bool isNull() const { return d == Data::sharedNull(); } bool isSimpleText() const; @@ -642,11 +632,8 @@ private: QString &operator=(const QByteArray &a); #endif - static const QStaticStringData<1> shared_null; - static const QStaticStringData<1> shared_empty; Data *d; - static void free(Data *); void reallocData(uint alloc, bool grow = false); void expand(int i); void updateProperties() const; @@ -903,8 +890,8 @@ inline void QCharRef::setRow(uchar arow) { QChar(*this).setRow(arow); } inline void QCharRef::setCell(uchar acell) { QChar(*this).setCell(acell); } -inline QString::QString() : d(shared_null.data_ptr()) {} -inline QString::~QString() { if (!d->ref.deref()) free(d); } +inline QString::QString() : d(Data::sharedNull()) {} +inline QString::~QString() { if (!d->ref.deref()) Data::deallocate(d); } inline void QString::reserve(int asize) { @@ -1179,7 +1166,7 @@ public: inline const QChar *unicode() const { if (!m_string) - return reinterpret_cast(QString::shared_null.str.data()); + return reinterpret_cast(QString::Data::sharedNull()->data()); return m_string->unicode() + m_position; } inline const QChar *data() const { return unicode(); } -- cgit v1.2.3 From c0d249019b098890fb8e5e9e144c2dd8029a670c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 13 Apr 2012 13:37:56 +0200 Subject: Allow qDebug output to be configured by qSetMessagePattern() Add qSetMessagePattern() to configure the default message pattern. This one can still be overwritten by setting the QT_MESSAGE_PATTERN environment variable. Without this method, there's actually no way to change the default output programatically. Since QT_MESSAGE_PATTERN is evaluated when the first message arrives, setting it via e.g. qputenv might have no effect/be too late. Change-Id: I115e0c30606f128fdbf5c169a951ffa2a6a48517 Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.cpp | 33 +++++++++++ src/corelib/global/qlogging.cpp | 64 +++++++++++++++++----- src/corelib/global/qlogging.h | 2 + tests/auto/corelib/global/qlogging/app/main.cpp | 7 +++ .../auto/corelib/global/qlogging/tst_qlogging.cpp | 38 +++++++++++-- 5 files changed, 127 insertions(+), 17 deletions(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 7036b72f08..38ddd7bf97 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3088,5 +3088,38 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) instead. \sa QtMsgHandler, qInstallMessageHandler */ +/*! + \fn void qSetMessagePattern(const QString &pattern) + \relates + \since 5.0 + + \brief Changes the output of the default message handler. + + Allows to tweak the output of qDebug(), qWarning(), qCritical() and qFatal(). + + Following placeholders are supported: + + \table + \header \li Placeholder \li Description + \row \li \c %{appname} \li QCoreApplication::applicationName() + \row \li \c %{file} \li Path to source file + \row \li \c %{function} \li Function + \row \li \c %{line} \li Line in source file + \row \li \c %{message} \li The actual message + \row \li \c %{pid} \li QCoreApplication::applicationPid() + \row \li \c %{threadid} \li ID of current thread + \row \li \c %{type} \li "debug", "warning", "critical" or "fatal" + \endtable + + The default pattern is "%{message}". + + The pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN + environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is + set, the environment variable takes precedence. + + qSetMessagePattern() has no effect if a custom message handler is installed. + + \sa qInstallMessageHandler, Debugging Techniques + */ QT_END_NAMESPACE diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 1f5b121143..8726c18689 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -45,6 +45,7 @@ #include "qstring.h" #include "qvarlengtharray.h" #include "qdebug.h" +#include "qmutex.h" #ifndef QT_BOOTSTRAPPED #include "qcoreapplication.h" #include "qthread.h" @@ -400,21 +401,53 @@ static const char appnameTokenC[] = "%{appname}"; static const char threadidTokenC[] = "%{threadid}"; static const char emptyTokenC[] = ""; +static const char defaultPattern[] = "%{message}"; + + struct QMessagePattern { QMessagePattern(); ~QMessagePattern(); + void setPattern(const QString &pattern); + // 0 terminated arrays of literal tokens / literal or placeholder tokens const char **literals; const char **tokens; + + bool fromEnvironment; + static QBasicMutex mutex; }; +QBasicMutex QMessagePattern::mutex; + QMessagePattern::QMessagePattern() + : literals(0) + , tokens(0) + , fromEnvironment(false) { - QString pattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); - if (pattern.isEmpty()) { - pattern = QLatin1String("%{message}"); + const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); + if (envPattern.isEmpty()) { + setPattern(QLatin1String(defaultPattern)); + } else { + setPattern(envPattern); + fromEnvironment = true; } +} + +QMessagePattern::~QMessagePattern() +{ + for (int i = 0; literals[i] != 0; ++i) + delete [] literals[i]; + delete [] literals; + literals = 0; + delete [] tokens; + tokens = 0; +} + +void QMessagePattern::setPattern(const QString &pattern) +{ + delete [] tokens; + delete [] literals; // scanner QList lexemes; @@ -495,16 +528,6 @@ QMessagePattern::QMessagePattern() memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); } -QMessagePattern::~QMessagePattern() -{ - for (int i = 0; literals[i] != 0; ++i) - delete [] literals[i]; - delete [] literals; - literals = 0; - delete [] tokens; - tokens = 0; -} - Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) /*! @@ -515,6 +538,8 @@ Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, const QMessageLogCont { QString message; + QMutexLocker lock(&QMessagePattern::mutex); + QMessagePattern *pattern = qMessagePattern(); if (!pattern) { // after destruction of static QMessagePattern instance @@ -523,6 +548,10 @@ Q_CORE_EXPORT QString qMessageFormatString(QtMsgType type, const QMessageLogCont return message; } + // don't print anything if pattern was empty + if (pattern->tokens[0] == 0) + return message; + // we do not convert file, function, line literals to local encoding due to overhead for (int i = 0; pattern->tokens[i] != 0; ++i) { const char *token = pattern->tokens[i]; @@ -741,6 +770,14 @@ QtMsgHandler qInstallMsgHandler(QtMsgHandler h) return old; } +void qSetMessagePattern(const QString &pattern) +{ + QMutexLocker lock(&QMessagePattern::mutex); + + if (!qMessagePattern()->fromEnvironment) + qMessagePattern()->setPattern(pattern); +} + void QMessageLogContext::copy(const QMessageLogContext &logContext) { this->category = logContext.category; @@ -748,4 +785,5 @@ void QMessageLogContext::copy(const QMessageLogContext &logContext) this->line = logContext.line; this->function = logContext.function; } + QT_END_NAMESPACE diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index 216b847952..ae388b0a38 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -168,6 +168,8 @@ Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler); typedef void (*QMessageHandler)(QtMsgType, const QMessageLogContext &, const char *); Q_CORE_EXPORT QMessageHandler qInstallMessageHandler(QMessageHandler); +Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern); + QT_END_HEADER QT_END_NAMESPACE diff --git a/tests/auto/corelib/global/qlogging/app/main.cpp b/tests/auto/corelib/global/qlogging/app/main.cpp index dfa52315c7..2f5a975e43 100644 --- a/tests/auto/corelib/global/qlogging/app/main.cpp +++ b/tests/auto/corelib/global/qlogging/app/main.cpp @@ -51,8 +51,15 @@ int main(int argc, char **argv) QCoreApplication app(argc, argv); app.setApplicationName("tst_qlogging"); + qSetMessagePattern("[%{type}] %{message}"); + qDebug("qDebug"); qWarning("qWarning"); qCritical("qCritical"); + + qSetMessagePattern(QString()); + + qDebug("qDebug2"); + return 0; } diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 1d6aa89035..5474b9aa3b 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -630,13 +630,16 @@ void tst_qmessagehandler::cleanupFuncinfo() void tst_qmessagehandler::qMessagePattern() { QProcess process; + const QString appExe = m_appDir + "/app"; + // + // test QT_MESSAGE_PATTERN + // QStringList environment = QProcess::systemEnvironment(); // %{file} is tricky because of shadow builds environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\""); process.setEnvironment(environment); - QString appExe = m_appDir + "/app"; process.start(appExe); QVERIFY2(process.waitForStarted(), qPrintable( QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString()))); @@ -649,9 +652,10 @@ void tst_qmessagehandler::qMessagePattern() QVERIFY(output.contains("debug 45 T::T static constructor")); // we can't be sure whether the QT_MESSAGE_PATTERN is already destructed QVERIFY(output.contains("static destructor")); - QVERIFY(output.contains("debug tst_qlogging 54 main qDebug")); - QVERIFY(output.contains("warning tst_qlogging 55 main qWarning")); - QVERIFY(output.contains("critical tst_qlogging 56 main qCritical")); + QVERIFY(output.contains("debug tst_qlogging 56 main qDebug")); + QVERIFY(output.contains("warning tst_qlogging 57 main qWarning")); + QVERIFY(output.contains("critical tst_qlogging 58 main qCritical")); + QVERIFY(output.contains("debug tst_qlogging 62 main qDebug2")); environment = QProcess::systemEnvironment(); environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\""); @@ -668,6 +672,32 @@ void tst_qmessagehandler::qMessagePattern() QVERIFY(output.contains("QT_MESSAGE_PATTERN: Unknown placeholder %{unknown}")); QVERIFY(output.contains("PREFIX: qDebug")); + + // + // test qSetMessagePattern + // + QMutableListIterator iter(environment); + while (iter.hasNext()) { + if (iter.next().startsWith("QT_MESSAGE_PATTERN")) + iter.remove(); + } + process.setEnvironment(environment); + + process.start(appExe); + QVERIFY2(process.waitForStarted(), qPrintable( + QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString()))); + process.waitForFinished(); + + output = process.readAllStandardError(); + //qDebug() << output; + QByteArray expected = "static constructor\n" + "[debug] qDebug\n" + "[warning] qWarning\n" + "[critical] qCritical\n"; +#ifdef Q_OS_WIN + output.replace("\r\n", "\n"); +#endif + QCOMPARE(QString::fromLatin1(output), QString::fromLatin1(expected)); } QTEST_MAIN(tst_qmessagehandler) -- cgit v1.2.3