Skip to content

Commit

Permalink
Logging: use qCDebug/Warning/Info when for categorized logging
Browse files Browse the repository at this point in the history
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.8 6.7 6.5
Change-Id: I968b0e826871a09023c11fec9e51caa5a2c4dc0b
Reviewed-by: Jonas Karlsson <[email protected]>
  • Loading branch information
vohi committed Jul 16, 2024
1 parent 6aa1cb0 commit 1e1c680
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/corelib/kernel/qcoreapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/corelib/plugin/qlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/text/qdistancefield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
48 changes: 24 additions & 24 deletions src/gui/util/qktxhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -141,27 +141,27 @@ 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();
}

// File contains key/values
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();
}
Expand All @@ -177,20 +177,20 @@ 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();
}

quint32 offset = headerKeyValueSize;
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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -304,41 +304,41 @@ 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;
}

const quint32 keySize = idx + 1; // Actual data size

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;
}

output.insert(keyView.toByteArray(), valueView.toByteArray());

const auto offsetNext = nearestMultipleOf4(offsetKeyAndValueEnd);
if (!offsetNext) {
qWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
qCWarning(lcQtGuiTextureIO, "Overflow in KTX key-value");
return std::nullopt;
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/vulkan/qbasicvulkanplatforminstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/vulkan/qvulkanwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/network/kernel/qnetconmonitor_darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,20 @@ qt_sockaddr qt_hostaddress_to_sockaddr(const QHostAddress &src)

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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/platformthemes/gtk3/qgtk3json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tls/openssl/qdtls_openssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tls/openssl/qx509_openssl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down

0 comments on commit 1e1c680

Please sign in to comment.