本文整理汇总了C++中QBluetoothServiceInfo::socketProtocol方法的典型用法代码示例。如果您正苦于以下问题:C++ QBluetoothServiceInfo::socketProtocol方法的具体用法?C++ QBluetoothServiceInfo::socketProtocol怎么用?C++ QBluetoothServiceInfo::socketProtocol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBluetoothServiceInfo
的用法示例。
在下文中一共展示了QBluetoothServiceInfo::socketProtocol方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listen
int QDeclarativeBluetoothServicePrivate::listen() {
if (m_service->socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) {
qWarning() << "Unknown protocol, can't make service" << m_protocol;
return -1;
}
QBluetoothServiceInfo::Protocol serverType = QBluetoothServiceInfo::UnknownProtocol;
if (m_service->socketProtocol() == QBluetoothServiceInfo::L2capProtocol)
serverType = QBluetoothServiceInfo::L2capProtocol;
else if (m_service->socketProtocol() == QBluetoothServiceInfo::RfcommProtocol)
serverType = QBluetoothServiceInfo::RfcommProtocol;
QBluetoothServer *server = new QBluetoothServer(serverType);
server->setMaxPendingConnections(1);
server->listen(QBluetoothAddress());
server->serverPort();
m_server = server;
return server->serverPort();
}
示例2: connected
/*!
Attempts to connect to the service described by \a service.
The socket is opened in the given \a openMode. The \l socketType() may change
depending on the protocol required by \a service.
The socket first enters ConnectingState and attempts to connect to the device providing
\a service. If a connection is established, QBluetoothSocket enters ConnectedState and
emits connected().
At any point, the socket can emit error() to signal that an error occurred.
Note that most platforms require a pairing prior to connecting to the remote device. Otherwise
the connection process may fail.
\sa state(), disconnectFromService()
*/
void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, OpenMode openMode)
{
Q_D(QBluetoothSocket);
if (state() != QBluetoothSocket::UnconnectedState && state() != QBluetoothSocket::ServiceLookupState) {
qCWarning(QT_BT) << "QBluetoothSocket::connectToService called on busy socket";
d->errorString = QBluetoothSocket::tr("Trying to connect while connection is in progress");
setSocketError(QBluetoothSocket::OperationError);
return;
}
#if defined(QT_QNX_BLUETOOTH) || defined(QT_ANDROID_BLUETOOTH)
if (!d->ensureNativeSocket(service.socketProtocol())) {
d->errorString = tr("Socket type not supported");
setSocketError(QBluetoothSocket::UnsupportedProtocolError);
return;
}
d->connectToService(service.device().address(), service.serviceUuid(), openMode);
#else
if (service.protocolServiceMultiplexer() > 0) {
if (!d->ensureNativeSocket(QBluetoothServiceInfo::L2capProtocol)) {
d->errorString = tr("Unknown socket error");
setSocketError(UnknownSocketError);
return;
}
d->connectToService(service.device().address(), service.protocolServiceMultiplexer(), openMode);
} else if (service.serverChannel() > 0) {
if (!d->ensureNativeSocket(QBluetoothServiceInfo::RfcommProtocol)) {
d->errorString = tr("Unknown socket error");
setSocketError(UnknownSocketError);
return;
}
d->connectToService(service.device().address(), service.serverChannel(), openMode);
} else {
// try doing service discovery to see if we can find the socket
if(service.serviceUuid().isNull()){
qCWarning(QT_BT) << "No port, no PSM, and no UUID provided, unable to connect";
return;
}
qCDebug(QT_BT) << "Need a port/psm, doing discovery";
doDeviceDiscovery(service, openMode);
}
#endif
}
示例3: tst_assignment
//.........这里部分代码省略.........
QCOMPARE(copyInfo2.device().address(), deviceInfo.address());
}
{
QBluetoothServiceInfo copyInfo;
QVERIFY(!copyInfo.isValid());
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!copyInfo.isComplete());
copyInfo = serviceInfo;
QVERIFY(copyInfo.contains(QBluetoothServiceInfo::ServiceName));
copyInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, QBluetoothUuid(uuid));
QVERIFY(copyInfo.contains(QBluetoothServiceInfo::ProtocolDescriptorList));
QVERIFY(copyInfo.isComplete());
QVERIFY(copyInfo.attributes().count() > 0);
copyInfo.removeAttribute(QBluetoothServiceInfo::ProtocolDescriptorList);
QVERIFY(!copyInfo.contains(QBluetoothServiceInfo::ProtocolDescriptorList));
QVERIFY(!copyInfo.isComplete());
}
{
QBluetoothServiceInfo copyInfo;
QVERIFY(!copyInfo.isValid());
copyInfo = serviceInfo;
QVERIFY(copyInfo.serverChannel() == -1);
QVERIFY(copyInfo.protocolServiceMultiplexer() == -1);
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(protocolUuid));
protocolDescriptorList.append(QVariant::fromValue(protocol));
protocol.clear();
protocolDescriptorList.append(QVariant::fromValue(protocol));
copyInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
protocolDescriptorList);
if (serviceInfoProtocol == QBluetoothServiceInfo::L2capProtocol) {
QVERIFY(copyInfo.serverChannel() == -1);
QVERIFY(copyInfo.protocolServiceMultiplexer() != -1);
} else if (serviceInfoProtocol == QBluetoothServiceInfo::RfcommProtocol) {
QVERIFY(copyInfo.serverChannel() != -1);
QVERIFY(copyInfo.protocolServiceMultiplexer() == -1);
}
QVERIFY(copyInfo.socketProtocol() == serviceInfoProtocol);
}
{
QBluetoothServiceInfo copyInfo;
QVERIFY(!copyInfo.isValid());
copyInfo = serviceInfo;
copyInfo.setServiceUuid(QBluetoothUuid::SerialPort);
QVERIFY(!copyInfo.isRegistered());
if (!QBluetoothLocalDevice::allDevices().count()) {
QSKIP("Skipping test due to missing Bluetooth device");
} else if (protocolSupported) {
QBluetoothServer server(serviceInfoProtocol);
QVERIFY(server.listen());
QTRY_VERIFY_WITH_TIMEOUT(server.isListening(), 5000);
QVERIFY(server.serverPort() > 0);
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
if (serviceInfoProtocol == QBluetoothServiceInfo::L2capProtocol) {
protocol << QVariant::fromValue(server.serverPort());
protocolDescriptorList.append(QVariant::fromValue(protocol));
} else if (serviceInfoProtocol == QBluetoothServiceInfo::RfcommProtocol) {
protocolDescriptorList.append(QVariant::fromValue(protocol));
protocol.clear();
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(quint8(server.serverPort()));
protocolDescriptorList.append(QVariant::fromValue(protocol));
}
serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
protocolDescriptorList);
QVERIFY(copyInfo.registerService());
QVERIFY(copyInfo.isRegistered());
QVERIFY(serviceInfo.isRegistered());
QBluetoothServiceInfo secondCopy;
secondCopy = copyInfo;
QVERIFY(secondCopy.isRegistered());
QVERIFY(secondCopy.unregisterService());
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!secondCopy.isRegistered());
QVERIFY(!serviceInfo.isRegistered());
QVERIFY(server.isListening());
server.close();
QVERIFY(!server.isListening());
}
}
}