{
Q_OBJECT
public:
- explicit BtConnector(QObject *parent = 0){qDebug("BtConnector Constructor");}
- ~BtConnector(){if(socket != NULL) delete socket;}
+ explicit BtConnector(QObject *parent = 0){
+
+ }
+ ~BtConnector(){
+ if(socket)
+ delete socket;
+ }
Q_INVOKABLE void connect(QString address, int port){
qDebug("Trying to connect to: %s--%d", address.toUtf8().constData(), port);
- if(socket != NULL)
+ if(socket)
delete socket;
+
socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket);
QObject::connect(socket, SIGNAL(connected()), this, SIGNAL(connected()));
QObject::connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
public slots:
void disconnect(){
- if(socket == NULL)
+ if(!socket)
return;
if(socket->isOpen())
socket->close();
delete socket;
+ socket = 0;
}
signals:
}
}
- qDebug("Button map: %d", buttonMap);
+// qDebug("Button map: %d", buttonMap);
emit(buttonsChanged(buttonMap & 0x01, buttonMap & 0x02, buttonMap & 0x04, buttonMap & 0x08));
}
}
Page {
tools: commonTools
- Label {
- id: label
- anchors.centerIn: parent
- text: "Press to connect."
- }
- Button{
- id: connectButton
- anchors {
- horizontalCenter: parent.horizontalCenter
- top: label.bottom
- topMargin: 10
- }
+ Column {
+ anchors.centerIn: parent
+ spacing: 10
- text: "Connect"
+ Label {
+ id: label
- onClicked: {
- btDiscovery.discovery = true
+ text: "Press to connect."
}
- }
- Button{
- id: disconnectButton
+ Button{
+ id: connectButton
- anchors {
- horizontalCenter: parent.horizontalCenter
- top: connectButton.bottom
- topMargin: 10
+ text: "Connect"
+
+ onClicked: {
+ btDiscovery.discovery = true
+ }
}
- text: "Disconnect"
+ Button{
+ id: disconnectButton
- onClicked: {
- btConn.disconnect()
+ text: "Disconnect"
+
+ onClicked: {
+ btConn.disconnect()
+ }
}
}