diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index 0ffa186d2e..a23e545729 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -443,4 +443,17 @@ bool QMimeType::inherits(const QString &mimeTypeName) const return QMimeDatabasePrivate::instance()->inherits(d->name, mimeTypeName); } +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QMimeType &mime) +{ + QDebugStateSaver saver(debug); + if (!mime.isValid()) { + debug.nospace() << "QMimeType(invalid)"; + } else { + debug.nospace() << "QMimeType(" << mime.name() << ")"; + } + return debug; +} +#endif + QT_END_NAMESPACE diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h index 24d043eebc..d5acbc2184 100644 --- a/src/corelib/mimetypes/qmimetype.h +++ b/src/corelib/mimetypes/qmimetype.h @@ -110,5 +110,10 @@ protected: Q_DECLARE_SHARED(QMimeType) +#ifndef QT_NO_DEBUG_STREAM +class QDebug; +Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime); +#endif + QT_END_NAMESPACE #endif // QMIMETYPE_H diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 890f9f8dcb..07e011f449 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -211,6 +211,8 @@ void tst_QDebug::debugSpaceHandling() const QCOMPARE(s_msg, QString::fromLatin1("QPoint(21,22) QRect(23,24 25x26) QLine(QPoint(27,28),QPoint(29,30))")); qDebug() << QPointF(21, 22) << QRectF(23, 24, 25, 26) << QLineF(27, 28, 29, 30); QCOMPARE(s_msg, QString::fromLatin1("QPointF(21,22) QRectF(23,24 25x26) QLineF(QPointF(27,28),QPointF(29,30))")); + qDebug() << QMimeType() << QMimeDatabase().mimeTypeForName("application/pdf") << "foo"; + QCOMPARE(s_msg, QString::fromLatin1("QMimeType(invalid) QMimeType(\"application/pdf\") foo")); } void tst_QDebug::stateSaver() const