brennie
brennie

Reputation: 543

qt and libbluedevil: No Such slot

I am trying to connect to BlueDevil::Manager::devicesChanged, but when I run my program I get the error Object::connect: No such slot Handler::changed(QList<Device*>) in src/handler.cpp:26 How can I fix this error? As far as I can see, changed has the correct type.

main.cpp:

#include <QApplication>

#include "handler.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    Handler handler;

    return app.exec();
}

handler.h:

#include <bluedevil/bluedevil.h>

#include <iostream>

#include <QObject>

class Handler : public QObject
{
    Q_OBJECT

    public:
        Handler();

    public Q_SLOTS:
        void changed(const QList<BlueDevil::Device*> &devices);

    private:
        BlueDevil::Manager *manager;
        BlueDevil::Adapter *defaultAdapter;
};

handler.cpp

#include <bluedevil/bluedevil.h>

#include <iostream>

#include <QObject>

#include "handler.h"


using namespace BlueDevil;

void Handler::changed(const QList<Device*> &devices)
{
    Q_FOREACH (const Device *device, devices)
    {
        std::cout << qPrintable(device->friendlyName()) << std::endl;
    }
}

Handler::Handler() : QObject()
{
    manager = Manager::self();
    defaultAdapter = manager->defaultAdapter();

    connect(defaultAdapter, SIGNAL(devicesChanged(QList<Device*>)),
            this, SLOT(changed(QList<Device*>)));

}

Upvotes: 0

Views: 283

Answers (1)

Mat
Mat

Reputation: 206861

Try with:

connect(defaultAdapter, SIGNAL(devicesChanged(QList<BlueDevil::Device*>)),
        this, SLOT(changed(QList<BlueDevil::Device*>)));

SIGNAL and SLOT are macros, they can't really be namespace-aware.

If that doesn't work, try:

connect(defaultAdapter, SIGNAL(devicesChanged(QList<Device*>)),
        this, SLOT(changed(QList<BlueDevil::Device*>)));

... and if that doesn't work, you'll have to put using namespace BlueDevil; in your header, and declare your slot with:

void changed(const QList<Device*> &devices);

and use your original connection. This is a bit sad.

Upvotes: 1

Related Questions