Facing error in no matching function for call in qdbusabstractinterface

41 views Asked by At

I am trying to pass a array of int as one of the parameter in QDBusPendingCall asyncCall = interface.asyncCall("Message", type, indices, message); where interface is QDBusInterface object. And the parameters type is of int, indices is of array of int and message is of qString.

To pass as array of int, I have tried with std::array<int,1> , QList<int> and QVector<int>. For all three ways, I am getting the below error during build process.

error: no matching function for call to 'QVariant::QVariant(QVector<int>&)'
|   168 |         const QVariant variants[] = { QVariant(std::forward<Args>(args))... };
|       |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This error traces back to qdbusabstractinterface.h file in QT.

But if I try with passing a value directly in the function call, there is no such error during build process.

**Example:

myclass.h**

#ifndef MYCLASS_H
#define MYCLASS_H

#include <QObject>
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
#include <QVector>

class MyClass : public QObject
{
    Q_OBJECT

public:
    explicit MyClass(QObject *parent = nullptr);

public slots:
    void performDistributedCalculation(int type, QVector<int> indices, QString message);

private slots:
    void handleDBusReply(QDBusPendingCallWatcher *watcher);

private:
    QDBusInterface interface;
};

#endif // MYCLASS_H

**myclass.cpp**

#include "myclass.h"

MyClass::MyClass(QObject *parent) : QObject(parent)
{
    // Create the D-Bus interface
    interface = new QDBusInterface("com.example.MyService", "/MyObject", "org.example.MyInterface", QDBusConnection::sessionBus(), this);
}

void MyClass::performDistributedCalculation(int type, QVector<int> indices, QString message)
{
    // Asynchronously call the D-Bus method
    QDBusPendingCall asyncCall =interface.asyncCall("Message", type, indices, message);

    // Connect the reply handler
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
    connect(watcher, &QDBusPendingCallWatcher::finished, this, &MyClass::handleDBusReply);
}

void MyClass::handleDBusReply(QDBusPendingCallWatcher *watcher)
{
    QDBusPendingReply<int> reply = *watcher;
    if (reply.isError()) {
        qDebug() << "Error calling D-Bus method:" << reply.error().message();
    } else {
        int result = reply.value();
        qDebug() << "Received result from D-Bus:" << result;
        // Handle the result as needed
    }

    watcher->deleteLater();
}

**main.cpp**

#include <QCoreApplication>
#include "myclass.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    myclass myObject;
    myObject.performDistributedCalculation(2 , {1,2}, "HELLO, I am fine");

    return a.exec();
}

Can anyone guide me to resolve this?

0

There are 0 answers