2016-08-20 126 views
0

在我的程序連接到本地藍牙地址時,類QBluetoothSocket發出信號connected(),所以我在構造函數中捕獲它並調用一個信息插槽,它表示連接已建立。 但我不知道爲什麼,信息插槽是隱形的。
希望用代碼更容易理解。連接不起作用

QBluetoothSocket socket; 
connect(socket,&QBluetoothSocket::connected,this,&Widget::connected_to_local) 
void Widget::connected_to_local() 
{ 
    qDebug()<<"Connected!"<<endl; 
} 

和錯誤是:

C:\Qt_Projects\A_for_w8\A_for_w8\widget.cpp:19: error: no matching function for call to 'Widget::connect(QBluetoothSocket&, void (QBluetoothSocket::*)(), Widget*, void (Widget::*)())' 
     connect(socket,&QBluetoothSocket::connected,this,&Widget::connected_to_local) 
                       ^

我只好忍痛流淚,但真的不知道爲什麼.. 希望能對你有所幫助。

+2

'連接(插座,...'? – LogicStuff

回答

0

你可以這樣做:

QBluetoothSocket *socket = new QBluetoothSocket(); 
connect(socket,&QBluetoothSocket::connected,this,&Widget::connected_to_local) 
void Widget::connected_to_local() 
{ 
    qDebug()<<"Connected!"<<endl; 
} 

或:

QBluetoothSocket socket; 
connect(&socket,&QBluetoothSocket::connected,this,&Widget::connected_to_local) 
void Widget::connected_to_local() 
{ 
    qDebug()<<"Connected!"<<endl; 
} 

你可以找到更多的相關信息on the docs