Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlloggingcategory.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 Pelagicore AG
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtQml/qqmlinfo.h>
7
8#include <memory>
9
86 : QObject(parent)
87 , m_initialized(false)
88{
89}
90
94
96{
97 return QString::fromUtf8(m_name);
98}
99
104
106{
107 return m_category.get();
108}
109
113
115{
116 m_initialized = true;
117 if (m_name.isNull()) {
118 qmlWarning(this) << QLatin1String("Declaring the name of a LoggingCategory is mandatory and cannot be changed later");
119 } else {
120 auto category = std::make_unique<QLoggingCategory>(m_name.constData(), QtMsgType(m_defaultLogLevel));
121 m_category.swap(category);
122 }
123}
124
126{
127 if (m_defaultLogLevel == defaultLogLevel)
128 return;
129
130 if (m_initialized) {
131 qmlWarning(this) << QLatin1String("The defaultLogLevel of a LoggingCategory cannot be changed after the component is completed");
132 return;
133 }
134
135 m_defaultLogLevel = defaultLogLevel;
136}
137
139{
140 const QByteArray newName = name.toUtf8();
141
142 if (m_name == newName)
143 return;
144
145 if (m_initialized) {
146 qmlWarning(this) << QLatin1String("The name of a LoggingCategory cannot be changed after the component is completed");
147 return;
148 }
149
150 m_name = newName;
151}
152
153#include "moc_qqmlloggingcategory_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
bool isNull() const noexcept
Returns true if this byte array is null; otherwise returns false.
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
void setDefaultLogLevel(DefaultLogLevel defaultLogLevel)
void setName(const QString &name)
QLoggingCategory * category() const
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQmlLoggingCategory(QObject *parent=nullptr)
\qmltype LoggingCategory\inqmlmodule QtQml
DefaultLogLevel defaultLogLevel
void classBegin() override
Invoked after class creation, but before any properties have been set.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
QtMsgType
Definition qlogging.h:29
GLuint name
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31