John John - 3 months ago 18
C++ Question

Connect does not work

In my program during connection to local Bluetooth address, class QBluetoothSocket emits signal connected(), so I catch it in constructor and call an informative slot, which says that connection was established.
But I do not know why, informative slot is invisible.

Hope with code it is easier to understand.

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


and error is:

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)
^


I tore myself in tears, but really have no idea why..
Hope you can help.

Answer

You can do this:

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

or:

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

You can find more infos on the docs

Comments