5 #include <QtConnectivity/QBluetoothAddress>
6 #include <QtConnectivity/QBluetoothSocket>
9 class BtConnector : public QObject
13 explicit BtConnector(QObject *parent = 0){qDebug("BtConnector Constructor");}
14 ~BtConnector(){if(socket != NULL) delete socket;}
16 Q_INVOKABLE void connect(QString address, int port){
17 qDebug("Trying to connect to: %s--%d", address.toUtf8().constData(), port);
21 socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
22 QObject::connect(socket, SIGNAL(connected()), this, SIGNAL(connected()));
23 QObject::connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
24 QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SIGNAL(error(QBluetoothSocket::SocketError)));
26 qDebug("Connecting...");
27 socket->connectToService(QBluetoothAddress(address), port);
30 QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
47 void error(QBluetoothSocket::SocketError errorCode);
49 void stickMoved(int x, int y);
53 qDebug("readData...");
54 QByteArray data = socket->readAll();
55 qDebug("read %d bytes.", data.size());
57 for(int i=0; i < data.size(); i++){
58 qDebug("%d: %d", i, ((signed char)data.at(i)));
63 QBluetoothSocket *socket;
67 #endif // BTCONNECTOR_H