2012-01-01 48 views
0

我想連接到BlueDevil::Manager::devicesChanged,但是當我運行我的程序時出現錯誤Object::connect: No such slot Handler::changed(QList<Device*>) in src/handler.cpp:26我該如何解決這個錯誤?據我所知,改變了正確的類型。qt和libbluedevil:沒有這樣的插槽

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*>))); 

} 

回答

1

嘗試用:

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

SIGNALSLOT是宏,它們不能真正是名稱空間感知的。

如果還是不行,請嘗試:

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

...如果不工作,你得把using namespace BlueDevil;在你的頭,並與您的聲明插槽:

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

並使用您的原始連接。這有點難過。

+0

如果我將其更改爲'BlueDevil :: Device',我在src/handler.cpp中得到'Object :: connect:No such signal BlueDevil :: Adapter :: devicesChanged(QList ): 23' – brennie 2012-01-01 20:00:13

+0

增加第二個選項,可以工作取決於BlueDevil文件的處理方式。 – Mat 2012-01-01 20:15:21

+0

'QObject :: connect:不兼容的發送者/接收者參數 BlueDevil :: Adapter :: devicesChanged(QList ) - > Handler :: changed(QList )' – brennie 2012-01-01 20:39:35

相關問題