Logging: use qCDebug/Warning/Info when for categorized logging

When building qt with QT_NO_DEBUG/WARNING/INFO_OUTPUT set, then the
qDebug/Warning/Info macros expand to `QMessageLogger::noDebug`. That
helper is not defined to take a logging category or category function,
so using `qDebug(lcX, ...)` breaks the build. The correct way to emit
categorized logging is to use the qCDebug/Warning/Info macros.

Task-number: QTBUG-125589
Pick-to: 6.7 6.5
Change-Id: I968b0e826871a09023c11fec9e51caa5a2c4dc0b
Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
(cherry picked from commit 1e1c68017338c89265d6664a27f4137fc8960473)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-07-16 11:46:39 +02:00 committed by Qt Cherry-pick Bot
parent 678dccb7ac
commit d2730bc303
12 changed files with 41 additions and 41 deletions

View File

@ -2922,7 +2922,7 @@ void QCoreApplication::requestPermission(const QPermission &requestedPermission,
Q_ASSERT(slotObj);
if (QThread::currentThread() != QCoreApplicationPrivate::mainThread()) {
qWarning(lcPermissions, "Permissions can only be requested from the GUI (main) thread");
qCWarning(lcPermissions, "Permissions can only be requested from the GUI (main) thread");
return;
}

View File

@ -364,7 +364,7 @@ inline void QLibraryStore::cleanup()
if (lcDebugLibrary().isDebugEnabled()) {
for (auto &[_, lib] : data->libraryMap) {
if (lib)
qDebug(lcDebugLibrary)
qCDebug(lcDebugLibrary)
<< "On QtCore unload," << lib->fileName << "was leaked, with"
<< lib->libraryRefCount.loadRelaxed() << "users";
}

View File

@ -732,7 +732,7 @@ static void initialDistanceFieldFactor()
}
if (qEnvironmentVariableIsSet("QT_DISTANCEFIELD_DEFAULT_RADIUS")) {
QT_DISTANCEFIELD_DEFAULT_RADIUS = qEnvironmentVariableIntValue("QT_DISTANCEFIELD_DEFAULT_RADIUS");
qDebug(lcDistanceField) << "set the QT_DISTANCEFIELD_DEFAULT_RADIUS:" << QT_DISTANCEFIELD_DEFAULT_RADIUS;
qCDebug(lcDistanceField) << "set the QT_DISTANCEFIELD_DEFAULT_RADIUS:" << QT_DISTANCEFIELD_DEFAULT_RADIUS;
}
if (qEnvironmentVariableIsSet("QT_DISTANCEFIELD_DEFAULT_HIGHGLYPHCOUNT")) {
QT_DISTANCEFIELD_DEFAULT_HIGHGLYPHCOUNT = qEnvironmentVariableIntValue("QT_DISTANCEFIELD_DEFAULT_HIGHGLYPHCOUNT");

View File

@ -754,7 +754,7 @@ void QWindowsDirectWriteFontDatabase::populateFontDatabase()
fontFamily->AddRef();
if (defaultLocaleName == defaultFontName && defaultFontName != systemDefaultFontName) {
qDebug(lcQpaFonts) << "Adding default font" << systemDefaultFontName << "as alternative to" << defaultLocaleName;
qCDebug(lcQpaFonts) << "Adding default font" << systemDefaultFontName << "as alternative to" << defaultLocaleName;
m_populatedFonts.insert(systemDefaultFontName, *fontFamily);
fontFamily->AddRef();
@ -767,7 +767,7 @@ void QWindowsDirectWriteFontDatabase::populateFontDatabase()
fontFamily->AddRef();
if (englishLocaleName == defaultFontName && defaultFontName != systemDefaultFontName) {
qDebug(lcQpaFonts) << "Adding default font" << systemDefaultFontName << "as alternative to" << englishLocaleName;
qCDebug(lcQpaFonts) << "Adding default font" << systemDefaultFontName << "as alternative to" << englishLocaleName;
m_populatedFonts.insert(systemDefaultFontName, *fontFamily);
fontFamily->AddRef();

View File

@ -106,24 +106,24 @@ QTextureFileData QKtxHandler::read()
const QByteArray buf = device()->readAll();
if (static_cast<size_t>(buf.size()) > std::numeric_limits<quint32>::max()) {
qWarning(lcQtGuiTextureIO, "Too big KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Too big KTX file %s", logName().constData());
return QTextureFileData();
}
if (!canRead(QByteArray(), buf)) {
qWarning(lcQtGuiTextureIO, "Invalid KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Invalid KTX file %s", logName().constData());
return QTextureFileData();
}
if (buf.size() < qsizetype(qktxh_headerSize)) {
qWarning(lcQtGuiTextureIO, "Invalid KTX header size in %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Invalid KTX header size in %s", logName().constData());
return QTextureFileData();
}
KTXHeader header;
memcpy(&header, buf.data(), qktxh_headerSize);
if (!checkHeader(header)) {
qWarning(lcQtGuiTextureIO, "Unsupported KTX file format in %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Unsupported KTX file format in %s", logName().constData());
return QTextureFileData();
}
@ -141,13 +141,13 @@ QTextureFileData QKtxHandler::read()
const quint32 bytesOfKeyValueData = decode(header.bytesOfKeyValueData);
quint32 headerKeyValueSize;
if (qAddOverflow(qktxh_headerSize, bytesOfKeyValueData, &headerKeyValueSize)) {
qWarning(lcQtGuiTextureIO, "Overflow in size of key value data in header of KTX file %s",
qCWarning(lcQtGuiTextureIO, "Overflow in size of key value data in header of KTX file %s",
logName().constData());
return QTextureFileData();
}
if (headerKeyValueSize >= quint32(buf.size())) {
qWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
return QTextureFileData();
}
@ -155,13 +155,13 @@ QTextureFileData QKtxHandler::read()
if (bytesOfKeyValueData > 0) {
auto keyValueDataView = safeView(buf, qktxh_headerSize, bytesOfKeyValueData);
if (keyValueDataView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "Invalid view in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Invalid view in KTX file %s", logName().constData());
return QTextureFileData();
}
auto keyValues = decodeKeyValues(keyValueDataView);
if (!keyValues) {
qWarning(lcQtGuiTextureIO, "Could not parse key values in KTX file %s",
qCWarning(lcQtGuiTextureIO, "Could not parse key values in KTX file %s",
logName().constData());
return QTextureFileData();
}
@ -177,12 +177,12 @@ QTextureFileData QKtxHandler::read()
{ header.pixelWidth, header.pixelHeight, header.pixelDepth }));
if (texData.numLevels() > maxLevels) {
qWarning(lcQtGuiTextureIO, "Too many levels in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Too many levels in KTX file %s", logName().constData());
return QTextureFileData();
}
if (texData.numFaces() != 1 && texData.numFaces() != 6) {
qWarning(lcQtGuiTextureIO, "Invalid number of faces in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Invalid number of faces in KTX file %s", logName().constData());
return QTextureFileData();
}
@ -190,7 +190,7 @@ QTextureFileData QKtxHandler::read()
for (int level = 0; level < texData.numLevels(); level++) {
const auto imageSizeView = safeView(buf, offset, sizeof(quint32));
if (imageSizeView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
return QTextureFileData();
}
@ -204,13 +204,13 @@ QTextureFileData QKtxHandler::read()
// Add image data and padding to offset
const auto padded = nearestMultipleOf4(imageSize);
if (!padded) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "Overflow in KTX file %s", logName().constData());
return QTextureFileData();
}
quint32 offsetNext;
if (qAddOverflow(offset, *padded, &offsetNext)) {
qWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
qCWarning(lcQtGuiTextureIO, "OOB request in KTX file %s", logName().constData());
return QTextureFileData();
}
@ -219,7 +219,7 @@ QTextureFileData QKtxHandler::read()
}
if (!texData.isValid()) {
qWarning(lcQtGuiTextureIO, "Invalid values in header of KTX file %s",
qCWarning(lcQtGuiTextureIO, "Invalid values in header of KTX file %s",
logName().constData());
return QTextureFileData();
}
@ -273,7 +273,7 @@ std::optional<QMap<QByteArray, QByteArray>> QKtxHandler::decodeKeyValues(QByteAr
while (offset < quint32(view.size())) {
const auto keyAndValueByteSizeView = safeView(view, offset, sizeof(quint32));
if (keyAndValueByteSizeView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
return std::nullopt;
}
@ -282,19 +282,19 @@ std::optional<QMap<QByteArray, QByteArray>> QKtxHandler::decodeKeyValues(QByteAr
quint32 offsetKeyAndValueStart;
if (qAddOverflow(offset, quint32(sizeof(quint32)), &offsetKeyAndValueStart)) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}
quint32 offsetKeyAndValueEnd;
if (qAddOverflow(offsetKeyAndValueStart, keyAndValueByteSize, &offsetKeyAndValueEnd)) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}
const auto keyValueView = safeView(view, offsetKeyAndValueStart, keyAndValueByteSize);
if (keyValueView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
return std::nullopt;
}
@ -304,13 +304,13 @@ std::optional<QMap<QByteArray, QByteArray>> QKtxHandler::decodeKeyValues(QByteAr
const int idx = keyValueView.indexOf('\0');
if (idx == -1) {
qWarning(lcQtGuiTextureIO, "Invalid key in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Invalid key in KTX key-value");
return std::nullopt;
}
const QByteArrayView keyView = safeView(view, offsetKeyAndValueStart, idx);
if (keyView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}
@ -318,19 +318,19 @@ std::optional<QMap<QByteArray, QByteArray>> QKtxHandler::decodeKeyValues(QByteAr
quint32 offsetValueStart;
if (qAddOverflow(offsetKeyAndValueStart, keySize, &offsetValueStart)) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}
quint32 valueSize;
if (qSubOverflow(keyAndValueByteSize, keySize, &valueSize)) {
qWarning(lcQtGuiTextureIO, "Underflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Underflow in KTX key-value");
return std::nullopt;
}
const QByteArrayView valueView = safeView(view, offsetValueStart, valueSize);
if (valueView.isEmpty()) {
qWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Invalid view in KTX key-value");
return std::nullopt;
}
@ -338,7 +338,7 @@ std::optional<QMap<QByteArray, QByteArray>> QKtxHandler::decodeKeyValues(QByteAr
const auto offsetNext = nearestMultipleOf4(offsetKeyAndValueEnd);
if (!offsetNext) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}

View File

@ -173,7 +173,7 @@ void QBasicPlatformVulkanInstance::init(QLibrary *lib)
m_supportedExtensions.append(ext);
}
}
qDebug(lcPlatVk) << "Supported Vulkan instance extensions:" << m_supportedExtensions;
qCDebug(lcPlatVk) << "Supported Vulkan instance extensions:" << m_supportedExtensions;
}
QVulkanInfoVector<QVulkanLayer> QBasicPlatformVulkanInstance::supportedLayers() const
@ -248,13 +248,13 @@ void QBasicPlatformVulkanInstance::initInstance(QVulkanInstance *instance, const
if (!m_supportedLayers.contains(layerName))
m_enabledLayers.removeAt(i--);
}
qDebug(lcPlatVk) << "Enabling Vulkan instance layers:" << m_enabledLayers;
qCDebug(lcPlatVk) << "Enabling Vulkan instance layers:" << m_enabledLayers;
for (int i = 0; i < m_enabledExtensions.size(); ++i) {
const QByteArray &extName(m_enabledExtensions[i]);
if (!m_supportedExtensions.contains(extName))
m_enabledExtensions.removeAt(i--);
}
qDebug(lcPlatVk) << "Enabling Vulkan instance extensions:" << m_enabledExtensions;
qCDebug(lcPlatVk) << "Enabling Vulkan instance extensions:" << m_enabledExtensions;
VkInstanceCreateInfo instInfo = {};
instInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;

View File

@ -378,7 +378,7 @@ QVulkanInfoVector<QVulkanExtension> QVulkanWindow::supportedDeviceExtensions()
exts.append(ext);
}
d->supportedDevExtensions.insert(physDev, exts);
qDebug(lcGuiVk) << "Supported device extensions:" << exts;
qCDebug(lcGuiVk) << "Supported device extensions:" << exts;
return exts;
}
}

View File

@ -229,20 +229,20 @@ bool QNetworkConnectionMonitor::startMonitoring()
auto queue = qt_reachability_queue();
if (!queue) {
qWarning(lcNetMon, "Failed to create a dispatch queue to schedule a probe on");
qCWarning(lcNetMon, "Failed to create a dispatch queue to schedule a probe on");
return false;
}
SCNetworkReachabilityContext context = {};
context.info = d;
if (!SCNetworkReachabilitySetCallback(d->probe, QNetworkConnectionMonitorPrivate::probeCallback, &context)) {
qWarning(lcNetMon, "Failed to set a reachability callback");
qCWarning(lcNetMon, "Failed to set a reachability callback");
return false;
}
if (!SCNetworkReachabilitySetDispatchQueue(d->probe, queue)) {
qWarning(lcNetMon, "Failed to schedule a reachability callback on a queue");
qCWarning(lcNetMon, "Failed to schedule a reachability callback on a queue");
return false;
}

View File

@ -249,7 +249,7 @@ bool QGtk3Json::load(QGtk3Storage::PaletteMap &map, const QString &fileName)
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &err);
if (err.error != QJsonParseError::NoError) {
qWarning(lcQGtk3Interface) << "Unable to parse Json document from" << fileName
qCWarning(lcQGtk3Interface) << "Unable to parse Json document from" << fileName
<< err.error << err.errorString();
return false;
}
@ -417,7 +417,7 @@ bool QGtk3Json::load(QGtk3Storage::PaletteMap &map, const QJsonDocument &doc)
break;
case QGtk3Storage::SourceType::Invalid:
qInfo(lcQGtk3Interface) << "Invalid source type for palette" << paletteName
qCInfo(lcQGtk3Interface) << "Invalid source type for palette" << paletteName
<< "Brush." << colorRoleName;
return false;
}

View File

@ -353,7 +353,7 @@ extern "C" long q_dgram_ctrl(BIO *bio, int cmd, long num, void *ptr)
// command.
if (!bio) {
qDebug(lcTlsBackend, "invalid 'bio' parameter (nullptr)");
qCDebug(lcTlsBackend, "invalid 'bio' parameter (nullptr)");
return -1;
}

View File

@ -256,7 +256,7 @@ QVariant x509ExtensionToValue(X509_EXTENSION *ext)
else if (meth->ext_free)
meth->ext_free(ext_internal);
else
qWarning(lcTlsBackend, "Cannot free an extension, a potential memory leak?");
qCWarning(lcTlsBackend, "Cannot free an extension, a potential memory leak?");
});
const char * hexString = nullptr; // The value returned by meth->i2s.

View File

@ -771,7 +771,7 @@ void tst_QHighDpi::mouseVelocity()
{
velocity = ev->points().first().velocity();
if (ev->buttons())
qDebug(lcTests) << "velocity" << velocity << ev;
qCDebug(lcTests) << "velocity" << velocity << ev;
}
};