diff options
Diffstat (limited to 'examples/bluetooth/btchat/chatserver.cpp')
-rw-r--r-- | examples/bluetooth/btchat/chatserver.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/examples/bluetooth/btchat/chatserver.cpp b/examples/bluetooth/btchat/chatserver.cpp index 863078fc..0b29b87b 100644 --- a/examples/bluetooth/btchat/chatserver.cpp +++ b/examples/bluetooth/btchat/chatserver.cpp @@ -42,6 +42,7 @@ #include <qbluetoothserver.h> #include <qbluetoothsocket.h> +#include <qbluetoothlocaldevice.h> //! [Service UUID] static const QLatin1String serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8"); @@ -57,7 +58,7 @@ ChatServer::~ChatServer() stopServer(); } -void ChatServer::startServer() +void ChatServer::startServer(const QBluetoothAddress& localAdapter) { if (rfcommServer) return; @@ -65,14 +66,23 @@ void ChatServer::startServer() //! [Create the server] rfcommServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); connect(rfcommServer, SIGNAL(newConnection()), this, SLOT(clientConnected())); - rfcommServer->listen(); + bool result = rfcommServer->listen(localAdapter); + if (!result) { + qWarning() << "Cannot bind chat server to" << localAdapter.toString(); + return; + } //! [Create the server] - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); + //serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); //! [Class Uuuid must contain at least 1 entry] QBluetoothServiceInfo::Sequence classId; - classId << QVariant::fromValue(QBluetoothUuid(serviceUuid)); + + classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort)); + serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, + classId); + + classId.prepend(QVariant::fromValue(QBluetoothUuid(serviceUuid))); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); //! [Class Uuuid must contain at least 1 entry] @@ -81,7 +91,7 @@ void ChatServer::startServer() serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, tr("Bt Chat Server")); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceDescription, tr("Example bluetooth chat server")); - serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("Nokia, QtDF")); + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceProvider, tr("qt-project.org")); //! [Service name, description and provider] //! [Service UUID set] @@ -107,7 +117,7 @@ void ChatServer::startServer() //! [Protocol descriptor list] //! [Register service] - serviceInfo.registerService(); + serviceInfo.registerService(localAdapter); //! [Register service] } @@ -146,7 +156,6 @@ void ChatServer::clientConnected() connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); clientSockets.append(socket); - emit clientConnected(socket->peerName()); } //! [clientConnected] |