summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp')
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp71
1 files changed, 12 insertions, 59 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index ff5f48b914..25d3abf67e 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -32,17 +32,6 @@ Q_FLAG(Options)
typedef QFlags<Enum> Flags;
//! [2]
-
-//! [3]
-int myValue = 10;
-int minValue = 2;
-int maxValue = 6;
-
-int boundedValue = qBound(minValue, myValue, maxValue);
-// boundedValue == 6
-//! [3]
-
-
//! [4]
if (!driver()->isOpen() || driver()->isOpenError()) {
qWarning("QSqlQuery::exec: database not open");
@@ -61,11 +50,6 @@ quint64 value = Q_UINT64_C(932838457459459);
//! [6]
-//! [7]
-void myMsgHandler(QtMsgType, const char *);
-//! [7]
-
-
//! [8]
qint64 value = Q_INT64_C(932838457459459);
//! [8]
@@ -226,37 +210,26 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2)
//! [23]
-#include <qapplication.h>
+#include <QApplication>
#include <stdio.h>
#include <stdlib.h>
-void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+QtMessageHandler originalHandler = nullptr;
+
+void logToFile(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
- QByteArray localMsg = msg.toLocal8Bit();
- const char *file = context.file ? context.file : "";
- const char *function = context.function ? context.function : "";
- switch (type) {
- case QtDebugMsg:
- fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtInfoMsg:
- fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtWarningMsg:
- fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtCriticalMsg:
- fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtFatalMsg:
- fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- }
+ QString message = qFormatLogMessage(type, context, msg);
+ static FILE *f = fopen("log.txt", "a");
+ fprintf(f, "%s\n", qPrintable(message));
+ fflush(f);
+
+ if (originalHandler)
+ *originalHandler(type, context, msg);
}
int main(int argc, char **argv)
{
- qInstallMessageHandler(myMessageOutput);
+ originalHandler = qInstallMessageHandler(logToFile);
QApplication app(argc, argv);
...
return app.exec();
@@ -480,16 +453,6 @@ QString result(int type, int n)
}
//! [qttrid_n_noop]
-//! [37]
-qWarning("%s: %s", qUtf8Printable(key), qUtf8Printable(value));
-//! [37]
-
-
-//! [qUtf16Printable]
-qWarning("%ls: %ls", qUtf16Printable(key), qUtf16Printable(value));
-//! [qUtf16Printable]
-
-
//! [38]
struct Point2D
{
@@ -589,11 +552,6 @@ qFuzzyCompare(0.0, 1.0e-200); // This will return false
qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
//! [46]
-//! [47]
-CApaApplication *myApplicationFactory();
-//! [47]
-
-
//! [49]
void myMessageHandler(QtMsgType, const QMessageLogContext &, const QString &);
//! [49]
@@ -621,11 +579,6 @@ template<> class QTypeInfo<A> : public QTypeInfoMerger<A, B, C, D> {};
... qOverload<int, const QString &>(&Foo::overloadedFunction)
//! [52]
-//! [53]
- ... QOverload<>::of(&Foo::overloadedFunction)
- ... QOverload<int, const QString &>::of(&Foo::overloadedFunction)
-//! [53]
-
//! [54]
struct Foo {
void overloadedFunction(int, const QString &);