qInstallMsgHandler got deprecated in Qt 5.
Change-Id: Icb6423c7d9f7e507ba36376b0af5ad183379c494
Reviewed-by: Martin Jones <martin.r.jones@gmail.com>
}
static QStringList warnings;
-static void msgHandler(QtMsgType, const char *warning)
+static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning)
{
- warnings << QString::fromUtf8(warning);
+ warnings << warning;
}
void tst_qqmlcomponent::qmlCreateParentReference()
QCOMPARE(engine.outputWarningsToStandardError(), true);
warnings.clear();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
QQmlComponent component(&engine, testFileUrl("createParentReference.qml"));
QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8());
QVERIFY(QMetaObject::invokeMethod(object, "createChild"));
delete object;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
engine.setOutputWarningsToStandardError(false);
QCOMPARE(engine.outputWarningsToStandardError(), false);
QCOMPARE(engine.outputWarningsToStandardError(), true);
warnings.clear();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
QCoreApplication::processEvents();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
engine.setOutputWarningsToStandardError(false);
QCOMPARE(engine.outputWarningsToStandardError(), false);
}
static int transientErrorsMsgCount = 0;
-static void transientErrorsMsgHandler(QtMsgType, const char *)
+static void transientErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &)
{
++transientErrorsMsgCount;
}
QQmlComponent component(&engine, testFileUrl("transientErrors.qml"));
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
QObject *object = component.create();
QVERIFY(object != 0);
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
QQmlComponent component(&engine, testFileUrl("transientErrors.2.qml"));
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
QObject *object = component.create();
QVERIFY(object != 0);
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
QVERIFY(object != 0);
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
delete object;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
}
delete context;
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
object->basicSignal();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
QObject *o = component.create();
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
delete o;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
}
QObject *o = component.create();
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
delete o;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
}
}
static QStringList messages;
-static void captureMsgHandler(QtMsgType, const char *msg)
+static void captureMsgHandler(QtMsgType, const QMessageLogContext &, const QString &msg)
{
- messages.append(QLatin1String(msg));
+ messages.append(msg);
}
void tst_qqmlecmascript::nonNotifyable()
QQmlComponent component(&engine, testFileUrl("nonNotifyable.qml"));
QV4Compiler::enableV4(true);
- QtMsgHandler old = qInstallMsgHandler(captureMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(captureMsgHandler);
messages.clear();
QObject *object = component.create();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QVERIFY(object != 0);
engine.rootContext()->setContextProperty("pendingEvents", &processor);
transientErrorsMsgCount = 0;
- QtMsgHandler old = qInstallMsgHandler(transientErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(transientErrorsMsgHandler);
QQmlComponent c(&engine, testFileUrl("bindingSuppression.qml"));
QObject *obj = c.create();
QVERIFY(obj != 0);
delete obj;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
}
}
static QStringList warnings;
-static void msgHandler(QtMsgType, const char *warning)
+static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &warning)
{
- warnings << QString::fromUtf8(warning);
+ warnings << warning;
}
void tst_qqmlengine::outputWarningsToStandardError()
QVERIFY(c.isReady() == true);
warnings.clear();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
QObject *o = c.create();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QVERIFY(o != 0);
delete o;
QCOMPARE(engine.outputWarningsToStandardError(), false);
- old = qInstallMsgHandler(msgHandler);
+ old = qInstallMessageHandler(msgHandler);
o = c.create();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QVERIFY(o != 0);
delete o;
};
static QStringList messages;
-static void msgHandler(QtMsgType, const char *msg)
+static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg)
{
- messages << QLatin1String(msg);
+ messages << msg;
}
void tst_qqmlinstruction::dump()
<< "-------------------------------------------------------------------------------";
messages = QStringList();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
data->dumpInstructions();
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(messages.count(), expect.count());
for (int ii = 0; ii < messages.count(); ++ii) {
namespace
{
QStringList messages;
- void msgHandler(QtMsgType, const char *msg)
+ void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg)
{
- messages << QLatin1String(msg);
+ messages << msg;
}
}
void tst_QQmlPropertyMap::metaObjectAccessibility()
{
messages.clear();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
QQmlEngine engine;
QCOMPARE(map.metaObject()->className(), "MyEnhancedPropertyMap");
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(messages.count(), 0);
}
}
static QString qquickworkerscript_lastWarning;
-static void qquickworkerscript_warningsHandler(QtMsgType type, const char *msg)
+static void qquickworkerscript_warningsHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
if (type == QtWarningMsg)
- qquickworkerscript_lastWarning = QString::fromUtf8(msg);
+ qquickworkerscript_lastWarning = msg;
}
void tst_QQuickWorkerScript::scriptError_onLoad()
{
QQmlComponent component(&m_engine, testFileUrl("worker_error_onLoad.qml"));
- QtMsgHandler previousMsgHandler = qInstallMsgHandler(qquickworkerscript_warningsHandler);
+ QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler);
QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
QVERIFY(worker != 0);
QTRY_COMPARE(qquickworkerscript_lastWarning,
testFileUrl("script_error_onLoad.js").toString() + QLatin1String(":3: SyntaxError: Unexpected identifier"));
- qInstallMsgHandler(previousMsgHandler);
+ qInstallMessageHandler(previousMsgHandler);
qApp->processEvents();
delete worker;
}
QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create());
QVERIFY(worker != 0);
- QtMsgHandler previousMsgHandler = qInstallMsgHandler(qquickworkerscript_warningsHandler);
+ QtMessageHandler previousMsgHandler = qInstallMessageHandler(qquickworkerscript_warningsHandler);
QVariant value;
QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value)));
QTRY_COMPARE(qquickworkerscript_lastWarning,
testFileUrl("script_error_onCall.js").toString() + QLatin1String(":4: ReferenceError: getData is not defined"));
- qInstallMsgHandler(previousMsgHandler);
+ qInstallMessageHandler(previousMsgHandler);
qApp->processEvents();
delete worker;
}
}
static int v4ErrorCount;
-static QList<QByteArray> v4ErrorMessages;
-static void v4ErrorsMsgHandler(QtMsgType, const char *message)
+static QList<QString> v4ErrorMessages;
+static void v4ErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &message)
{
- QByteArray m(message);
- v4ErrorMessages.append(m);
+ v4ErrorMessages.append(message);
- if (m.contains("QV4"))
+ if (message.contains("QV4"))
++v4ErrorCount;
}
v4ErrorCount = 0;
v4ErrorMessages.clear();
- QtMsgHandler old = qInstallMsgHandler(v4ErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(v4ErrorsMsgHandler);
QObject *o = component.create();
delete o;
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
if (v4ErrorCount) {
- foreach (const QByteArray &msg, v4ErrorMessages)
+ foreach (const QString &msg, v4ErrorMessages)
qDebug() << msg;
}
QEXPECT_FAIL("jsvalueHandling", "QTBUG-26951 - QJSValue has a different representation of NULL to QV8Engine", Continue);
}
static QStringList messages;
-static void msgHandler(QtMsgType, const char *msg)
+static void msgHandler(QtMsgType, const QMessageLogContext &, const QString &msg)
{
- messages << QLatin1String(msg);
+ messages << msg;
}
static QByteArray getAddress(int address)
QStringList expected;
messages = QStringList();
- QtMsgHandler old = qInstallMsgHandler(msgHandler);
+ QtMessageHandler old = qInstallMessageHandler(msgHandler);
QQmlJS::Bytecode bc;
#define DUMP_INSTR_IN_UNIT_TEST(I, FMT) { QQmlJS::V4InstrData<QQmlJS::V4Instr::I> i; memset(&i, 0, sizeof(i)); bc.append(i); }
bc.dump(start, end);
// ensure that the output was expected.
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QCOMPARE(messages.count(), expected.count());
for (int ii = 0; ii < messages.count(); ++ii) {
// Calculating the destination address of a null jump/branch instruction is tricky
#include <QQmlEngine>
#include <QQmlError>
-static QtMsgHandler testlibMsgHandler = 0;
-void msgHandlerFilter(QtMsgType type, const char *msg)
+static QtMessageHandler testlibMsgHandler = 0;
+void msgHandlerFilter(QtMsgType type, const QMessageLogContext &ctxt, const QString &msg)
{
if (type == QtCriticalMsg || type == QtFatalMsg)
- (*testlibMsgHandler)(type, msg);
+ (*testlibMsgHandler)(type, ctxt, msg);
}
class tst_examples : public QObject
void tst_examples::init()
{
if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets"))
- testlibMsgHandler = qInstallMsgHandler(msgHandlerFilter);
+ testlibMsgHandler = qInstallMessageHandler(msgHandlerFilter);
}
void tst_examples::cleanup()
{
if (!qstrcmp(QTest::currentTestFunction(), "sgsnippets"))
- qInstallMsgHandler(testlibMsgHandler);
+ qInstallMessageHandler(testlibMsgHandler);
}
/*
}
static int numberOfWarnings = 0;
-static void checkWarnings(QtMsgType, const char *msg)
+static void checkWarnings(QtMsgType, const QMessageLogContext &, const QString &msg)
{
- if (!QString(msg).contains("QGLContext::makeCurrent(): Failed."))
+ if (!msg.contains("QGLContext::makeCurrent(): Failed."))
numberOfWarnings++;
}
QTRY_VERIFY(image != 0);
image->setSource(SERVER_ADDR + QString("/no-such-file.png"));
- QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings);
+ QtMessageHandler previousMsgHandler = qInstallMessageHandler(checkWarnings);
// used to print "QTransform::translate with NaN called"
QPixmap pm = QPixmap::fromImage(window->grabWindow());
- qInstallMsgHandler(previousMsgHandler);
+ qInstallMessageHandler(previousMsgHandler);
QVERIFY(numberOfWarnings == 0);
delete image;
}
#endif
- static void errorMsgHandler(QtMsgType, const char *)
+ static void errorMsgHandler(QtMsgType, const QMessageLogContext &, const QString &)
{
++m_errorCount;
}
QQuickView *window = createView();
m_errorCount = 0;
- QtMsgHandler old = qInstallMsgHandler(errorMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(errorMsgHandler);
window->setSource(testFileUrl("parentBinding.qml"));
window->show();
// there should be no transient binding error
QVERIFY(!m_errorCount);
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
delete window;
}
QString warningMessage;
-void interceptWarnings(QtMsgType type, const char *msg)
+void interceptWarnings(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
Q_UNUSED( type );
warningMessage = msg;
void tst_qquickpositioners::test_conflictinganchors()
{
- QtMsgHandler oldMsgHandler = qInstallMsgHandler(interceptWarnings);
+ QtMessageHandler oldMsgHandler = qInstallMessageHandler(interceptWarnings);
QQmlEngine engine;
QQmlComponent component(&engine);
item = qobject_cast<QQuickItem*>(component.create());
QVERIFY(item);
QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow. Flow will not function."));
- qInstallMsgHandler(oldMsgHandler);
+ qInstallMessageHandler(oldMsgHandler);
delete item;
}
delete view;
}
-static void silentErrorsMsgHandler(QtMsgType, const char *)
+static void silentErrorsMsgHandler(QtMsgType, const QMessageLogContext &, const QString &)
{
}
{
QQuickView *view = new QQuickView;
QVERIFY(view);
- QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler);
+ QtMessageHandler old = qInstallMessageHandler(silentErrorsMsgHandler);
view->setSource(testFileUrl("error1.qml"));
- qInstallMsgHandler(old);
+ qInstallMessageHandler(old);
QVERIFY(view->status() == QQuickView::Error);
QVERIFY(view->errors().count() == 1);
delete view;