Remove unneeded const_casts

There is no reason to take the QDBusPendingCalls from the QVariant as
const and then cast them.
This commit is contained in:
Aleix Pol 2021-10-19 04:09:01 +02:00
parent 599bcbac56
commit 9135ad06ea
2 changed files with 5 additions and 5 deletions

View file

@ -45,7 +45,7 @@ DBusResponseWaiter::DBusResponseWaiter()
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
{ {
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(extractPendingCall(variant))) if (QDBusPendingCall* call = extractPendingCall(variant))
{ {
call->waitForFinished(); call->waitForFinished();
@ -77,7 +77,7 @@ DBusAsyncResponse::DBusAsyncResponse(QObject* parent)
void DBusAsyncResponse::setPendingCall(QVariant variant) void DBusAsyncResponse::setPendingCall(QVariant variant)
{ {
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(DBusResponseWaiter::instance()->extractPendingCall(variant))) if (QDBusPendingCall* call = DBusResponseWaiter::instance()->extractPendingCall(variant))
{ {
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(*call);
watcher->setProperty("pengingCallVariant", variant); watcher->setProperty("pengingCallVariant", variant);
@ -124,13 +124,13 @@ void DBusAsyncResponse::onTimeout()
Q_EMIT error(QStringLiteral("timeout when waiting dbus response!")); Q_EMIT error(QStringLiteral("timeout when waiting dbus response!"));
} }
const QDBusPendingCall* DBusResponseWaiter::extractPendingCall(QVariant& variant) const QDBusPendingCall* DBusResponseWaiter::extractPendingCall(QVariant& variant) const
{ {
for (int type : qAsConst(m_registered)) for (int type : qAsConst(m_registered))
{ {
if (variant.canConvert(QVariant::Type(type))) if (variant.canConvert(QVariant::Type(type)))
{ {
return reinterpret_cast<const QDBusPendingCall*>(variant.constData()); return static_cast<QDBusPendingCall*>(variant.value<void *>());
} }
} }

View file

@ -25,7 +25,7 @@ public:
///extract QDbusPendingCall from \p variant and blocks until completed ///extract QDbusPendingCall from \p variant and blocks until completed
Q_INVOKABLE QVariant waitForReply(QVariant variant) const; Q_INVOKABLE QVariant waitForReply(QVariant variant) const;
const QDBusPendingCall* extractPendingCall(QVariant& variant) const; QDBusPendingCall* extractPendingCall(QVariant& variant) const;
private: private:
DBusResponseWaiter(); DBusResponseWaiter();