本文整理汇总了C++中QBluetoothServiceInfo::setServiceName方法的典型用法代码示例。如果您正苦于以下问题:C++ QBluetoothServiceInfo::setServiceName方法的具体用法?C++ QBluetoothServiceInfo::setServiceName怎么用?C++ QBluetoothServiceInfo::setServiceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBluetoothServiceInfo
的用法示例。
在下文中一共展示了QBluetoothServiceInfo::setServiceName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tst_construction
void tst_QBluetoothServiceInfo::tst_construction()
{
const QString serviceName("My Service");
const QString alternateServiceName("Another ServiceName");
const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0);
const QBluetoothDeviceInfo alternatedeviceInfo(QBluetoothAddress("554433221100"), "Test Device2", 0);
QList<QBluetoothUuid::ProtocolUuid> protUuids;
//list taken from qbluetoothuuid.h
protUuids << QBluetoothUuid::Sdp;
protUuids << QBluetoothUuid::Udp;
protUuids << QBluetoothUuid::Rfcomm;
protUuids << QBluetoothUuid::Tcp;
protUuids << QBluetoothUuid::TcsBin;
protUuids << QBluetoothUuid::TcsAt;
protUuids << QBluetoothUuid::Att;
protUuids << QBluetoothUuid::Obex;
protUuids << QBluetoothUuid::Ip;
protUuids << QBluetoothUuid::Ftp;
protUuids << QBluetoothUuid::Http;
protUuids << QBluetoothUuid::Wsp;
protUuids << QBluetoothUuid::Bnep;
protUuids << QBluetoothUuid::Upnp;
protUuids << QBluetoothUuid::Hidp;
protUuids << QBluetoothUuid::HardcopyControlChannel;
protUuids << QBluetoothUuid::HardcopyDataChannel;
protUuids << QBluetoothUuid::HardcopyNotification;
protUuids << QBluetoothUuid::Avctp;
protUuids << QBluetoothUuid::Avdtp;
protUuids << QBluetoothUuid::Cmtp;
protUuids << QBluetoothUuid::UdiCPlain;
protUuids << QBluetoothUuid::McapControlChannel;
protUuids << QBluetoothUuid::McapDataChannel;
protUuids << QBluetoothUuid::L2cap;
{
QBluetoothServiceInfo serviceInfo;
QVERIFY(!serviceInfo.isValid());
QVERIFY(!serviceInfo.isComplete());
QVERIFY(!serviceInfo.isRegistered());
QCOMPARE(serviceInfo.serviceName(), QString());
QCOMPARE(serviceInfo.serviceDescription(), QString());
QCOMPARE(serviceInfo.serviceProvider(), QString());
QCOMPARE(serviceInfo.serviceUuid(), QBluetoothUuid());
QCOMPARE(serviceInfo.serviceClassUuids().count(), 0);
QCOMPARE(serviceInfo.attributes().count(), 0);
QCOMPARE(serviceInfo.serverChannel(), -1);
QCOMPARE(serviceInfo.protocolServiceMultiplexer(), -1);
foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0);
}
{
QBluetoothServiceInfo serviceInfo;
serviceInfo.setServiceName(serviceName);
serviceInfo.setDevice(deviceInfo);
QVERIFY(serviceInfo.isValid());
QVERIFY(!serviceInfo.isComplete());
QVERIFY(!serviceInfo.isRegistered());
QCOMPARE(serviceInfo.serviceName(), serviceName);
QCOMPARE(serviceInfo.device().address(), deviceInfo.address());
QBluetoothServiceInfo copyInfo(serviceInfo);
QVERIFY(copyInfo.isValid());
QVERIFY(!copyInfo.isComplete());
QVERIFY(!copyInfo.isRegistered());
QCOMPARE(copyInfo.serviceName(), serviceName);
QCOMPARE(copyInfo.device().address(), deviceInfo.address());
copyInfo.setAttribute(QBluetoothServiceInfo::ServiceName, alternateServiceName);
copyInfo.setDevice(alternatedeviceInfo);
QCOMPARE(copyInfo.serviceName(), alternateServiceName);
QCOMPARE(copyInfo.attribute(QBluetoothServiceInfo::ServiceName).toString(), alternateServiceName);
QCOMPARE(serviceInfo.serviceName(), alternateServiceName);
QCOMPARE(copyInfo.device().address(), alternatedeviceInfo.address());
QCOMPARE(serviceInfo.device().address(), alternatedeviceInfo.address());
foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
QCOMPARE(serviceInfo.protocolDescriptor(u).count(), 0);
foreach (QBluetoothUuid::ProtocolUuid u, protUuids)
QCOMPARE(copyInfo.protocolDescriptor(u).count(), 0);
}
}
示例2: populateDiscoveredServices
void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QBluetoothDeviceInfo &remoteDevice, const QList<QBluetoothUuid> &uuids)
{
/* Android doesn't provide decent SDP data. A list of uuids is close to meaning-less
*
* The following approach is chosen:
* - If we see an SPP service class and we see
* one or more custom uuids we match them up. Such services will always be SPP services.
* - If we see a custom uuid but no SPP uuid then we return
* BluetoothServiceInfo instance with just a servuceUuid (no service class set)
* - Any other service uuid will stand on its own.
* */
Q_Q(QBluetoothServiceDiscoveryAgent);
//find SPP and custom uuid
QBluetoothUuid uuid;
int sppIndex = -1;
QVector<int> customUuids;
for (int i = 0; i < uuids.count(); i++) {
uuid = uuids.at(i);
if (uuid.isNull())
continue;
//check for SPP protocol
bool ok = false;
quint16 uuid16 = uuid.toUInt16(&ok);
if (ok && uuid16 == QBluetoothUuid::SerialPort)
sppIndex = i;
//check for custom uuid
if (uuid.minimumSize() == 16)
customUuids.append(i);
}
for (int i = 0; i < uuids.count(); i++) {
if (i == sppIndex && !customUuids.isEmpty())
continue;
QBluetoothServiceInfo serviceInfo;
serviceInfo.setDevice(remoteDevice);
QBluetoothServiceInfo::Sequence protocolDescriptorList;
{
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap));
protocolDescriptorList.append(QVariant::fromValue(protocol));
}
if (customUuids.contains(i) && sppIndex > -1) {
//we have a custom uuid of service class type SPP
//set rfcomm protocol
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(0);
protocolDescriptorList.append(QVariant::fromValue(protocol));
//set SPP service class uuid
QBluetoothServiceInfo::Sequence classId;
classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
classId);
classId.prepend(QVariant::fromValue(uuids.at(i)));
serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId);
serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Serial Port Profile"));
serviceInfo.setServiceUuid(uuids.at(i));
} else if (sppIndex == i && customUuids.isEmpty()) {
//set rfcomm protocol
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(0);
protocolDescriptorList.append(QVariant::fromValue(protocol));
QBluetoothServiceInfo::Sequence classId;
classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
classId);
//also we need to set the custom uuid to the SPP uuid
//otherwise QBluetoothSocket::connectToService() would fail due to a missing service uuid
serviceInfo.setServiceUuid(uuids.at(i));
} else if (customUuids.contains(i)) {
//custom uuid but no serial port
serviceInfo.setServiceUuid(uuids.at(i));
}
//Check if the UUID is in the uuidFilter
if (!uuidFilter.isEmpty() && !uuidFilter.contains(serviceInfo.serviceUuid()))
continue;
serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList);
serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList,
QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
if (!customUuids.contains(i)) {
//if we don't have custom uuid use it as class id as well
QBluetoothServiceInfo::Sequence classId;
//.........这里部分代码省略.........
示例3: tst_assignment
void tst_QBluetoothServiceInfo::tst_assignment()
{
QFETCH(QUuid, uuid);
QFETCH(QBluetoothUuid::ProtocolUuid, protocolUuid);
QFETCH(QBluetoothServiceInfo::Protocol, serviceInfoProtocol);
QFETCH(bool, protocolSupported);
const QString serviceName("My Service");
const QBluetoothDeviceInfo deviceInfo(QBluetoothAddress("001122334455"), "Test Device", 0);
QBluetoothServiceInfo serviceInfo;
serviceInfo.setServiceName(serviceName);
serviceInfo.setDevice(deviceInfo);
QVERIFY(serviceInfo.isValid());
QVERIFY(!serviceInfo.isRegistered());
QVERIFY(!serviceInfo.isComplete());
{
QBluetoothServiceInfo copyInfo = serviceInfo;
QVERIFY(copyInfo.isValid());
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!copyInfo.isComplete());
QCOMPARE(copyInfo.serviceName(), serviceName);
QCOMPARE(copyInfo.device().address(), deviceInfo.address());
}
{
QBluetoothServiceInfo copyInfo;
QVERIFY(!copyInfo.isValid());
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!copyInfo.isComplete());
copyInfo = serviceInfo;
QVERIFY(copyInfo.isValid());
QVERIFY(!copyInfo.isRegistered());
QVERIFY(!copyInfo.isComplete());
QCOMPARE(copyInfo.serviceName(), serviceName);
QCOMPARE(copyInfo.device().address(), deviceInfo.address());
}
{
QBluetoothServiceInfo copyInfo1;
QBluetoothServiceInfo copyInfo2;
QVERIFY(!copyInfo1.isValid());
QVERIFY(!copyInfo1.isRegistered());
QVERIFY(!copyInfo1.isComplete());
QVERIFY(!copyInfo2.isValid());
QVERIFY(!copyInfo2.isRegistered());
QVERIFY(!copyInfo2.isComplete());
copyInfo1 = copyInfo2 = serviceInfo;
QVERIFY(copyInfo1.isValid());
QVERIFY(!copyInfo1.isRegistered());
QVERIFY(!copyInfo1.isComplete());
QVERIFY(copyInfo2.isValid());
QVERIFY(!copyInfo2.isRegistered());
QVERIFY(!copyInfo2.isComplete());
QCOMPARE(copyInfo1.serviceName(), serviceName);
QCOMPARE(copyInfo2.serviceName(), serviceName);
QCOMPARE(copyInfo1.device().address(), deviceInfo.address());
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;
//.........这里部分代码省略.........