Skip to content

Commit

Permalink
Fix build errors from deprecated QVariant::type()
Browse files Browse the repository at this point in the history
    /build/source/src/platforms/linux/daemon/apptracker.cpp: In member function 'void AppTracker::userCreated(uint, const QString&)':
    /build/source/src/platforms/linux/daemon/apptracker.cpp:73:42: error: 'QVariant::Type QVariant::type() const' is deprecated: Use typeId() or metaType(). [-Werror=deprecated-declarations]
       73 |   if (!m_cgroupMount.isEmpty() && qv.type() == QVariant::String) {
          |                                   ~~~~~~~^~
    In file included from /nix/store/bgfalfi93kbn8j1wfwz0x0dnk1wx9wdp-qtbase-6.8.0/include/QtDBus/qtdbusglobal.h:9,
                     from /nix/store/bgfalfi93kbn8j1wfwz0x0dnk1wx9wdp-qtbase-6.8.0/include/QtDBus/qdbusconnection.h:8,
                     from /nix/store/bgfalfi93kbn8j1wfwz0x0dnk1wx9wdp-qtbase-6.8.0/include/QtDBus/QDBusConnection:1,
                     from /build/source/src/platforms/linux/daemon/apptracker.cpp:9:
    /nix/store/bgfalfi93kbn8j1wfwz0x0dnk1wx9wdp-qtbase-6.8.0/include/QtCore/qvariant.h:433:10: note: declared here
      433 |     Type type() const
          |          ^~~~

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Oct 15, 2024
1 parent 1b358d2 commit f58ccd9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/inspector/inspectorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static QList<InspectorCommand> s_commands{
Q_ASSERT(property.isValid());

QVariant value = QVariant::fromValue(arguments[3]);
if (!value.canConvert(property.type())) {
if (!value.canConvert(property.typeId())) {
obj["error"] = "Property value is invalid";
return obj;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ static QList<InspectorCommand> s_commands{
Q_ASSERT(property.isValid());

QVariant value = QVariant::fromValue(arguments[4]);
if (!value.canConvert(property.type())) {
if (!value.canConvert(property.typeId())) {
obj["error"] = "Property value is invalid";
return obj;
}
Expand Down Expand Up @@ -500,13 +500,13 @@ static QList<InspectorCommand> s_commands{
Q_ASSERT(property.isValid());

QVariant value = QVariant::fromValue(arguments[2]);
if (value.canConvert(property.type())) {
if (value.canConvert(property.typeId())) {
property.write(settingsHolder, value);
return obj;
}

obj["error"] = QString("Property %1 has a non-supported type: %2")
.arg(arguments[1], property.type());
.arg(arguments[1], property.typeName());
return obj;
}},

Expand Down Expand Up @@ -546,7 +546,7 @@ static QList<InspectorCommand> s_commands{
}

obj["error"] = QString("Property %1 has a non-supported type: %2")
.arg(arguments[1], property.type());
.arg(arguments[1], property.typeName());
return obj;
}},

Expand Down
3 changes: 2 additions & 1 deletion src/localsocketcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QMetaType>

#include "daemon/daemonerrors.h"
#include "errorhandler.h"
Expand Down Expand Up @@ -380,7 +381,7 @@ void LocalSocketController::clearTimeout(const QString& responseType) {
// here to add such a mechanism would risk a compatibility issue.
for (QTimer* t : m_responseTimeouts) {
QVariant timerResponseType = t->property("responseType");
if (timerResponseType.type() != QVariant::String) {
if (timerResponseType.typeId() != QMetaType::QString) {
continue;
}
if (timerResponseType.toString() != responseType) {
Expand Down
3 changes: 2 additions & 1 deletion src/platforms/linux/daemon/apptracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QDBusConnection>
#include <QDBusInterface>
#include <QMetaType>
#include <QScopeGuard>
#include <QtDBus/QtDBus>

Expand Down Expand Up @@ -70,7 +71,7 @@ void AppTracker::userCreated(uint userid, const QString& xdgRuntimePath) {
new QDBusInterface(DBUS_SYSTEMD_SERVICE, DBUS_SYSTEMD_PATH,
DBUS_SYSTEMD_MANAGER, connection, this);
QVariant qv = m_systemdInterface->property("ControlGroup");
if (!m_cgroupMount.isEmpty() && qv.type() == QVariant::String) {
if (!m_cgroupMount.isEmpty() && qv.typeId() == QMetaType::QString) {
QString userCgroupPath = m_cgroupMount + qv.toString();
logger.debug() << "Monitoring Control Groups v2 at:" << userCgroupPath;

Expand Down
6 changes: 4 additions & 2 deletions src/settings/setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "settings/setting.h"

#include <QMetaType>

#include "leakdetector.h"
#include "settingsmanager.h"

Expand Down Expand Up @@ -70,9 +72,9 @@ QString Setting::log() const {
logLine.append(QString("%1 -> ").arg(m_key));
QVariant value = get();
switch (value.typeId()) {
case QVariant::List:
case QMetaType::QVariantList:
[[fallthrough]];
case QVariant::StringList:
case QMetaType::QStringList:
logLine.append(QString("[%1]").arg(value.toStringList().join(",")));
break;
default:
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/testmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMetaType>

#include "constants.h"
#include "helper.h"
Expand Down Expand Up @@ -1632,9 +1633,9 @@ void TestModels::serverCountryModelFromJson() {
QCOMPARE(m.data(index, ServerCountryModel::CodeRole), code);

QFETCH(QVariant, cities);
Q_ASSERT(cities.typeId() == QVariant::List);
Q_ASSERT(cities.typeId() == QMetaType::QVariantList);
QVariant cityData = m.data(index, ServerCountryModel::CitiesRole);
QCOMPARE(cityData.typeId(), QVariant::List);
QCOMPARE(cityData.typeId(), QMetaType::QVariantList);
QCOMPARE(cities.toList().length(), cityData.toList().length());
for (int i = 0; i < cities.toList().length(); i++) {
QVERIFY(cityData.toList().at(0).canConvert<ServerCity*>());
Expand Down Expand Up @@ -1687,7 +1688,7 @@ void TestModels::serverCountryModelFromJson() {

QFETCH(QVariant, cities);
QVariant cityData = m.data(index, ServerCountryModel::CitiesRole);
QCOMPARE(cityData.typeId(), QVariant::List);
QCOMPARE(cityData.typeId(), QMetaType::QVariantList);
QCOMPARE(cities.toList().length(), cityData.toList().length());
for (int i = 0; i < cities.toList().length(); i++) {
QVERIFY(cityData.toList().at(0).canConvert<ServerCity*>());
Expand Down

0 comments on commit f58ccd9

Please sign in to comment.