本文整理汇总了C++中QBluetoothServiceInfo类的典型用法代码示例。如果您正苦于以下问题:C++ QBluetoothServiceInfo类的具体用法?C++ QBluetoothServiceInfo怎么用?C++ QBluetoothServiceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QBluetoothServiceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connected
/*!
Attempts to make a connection to the service identified by \a uuid on the device with address
\a address.
The socket is opened in the given \a openMode.
For BlueZ, the socket first enters the \l ServiceLookupState and queries the connection parameters for
\a uuid. If the service parameters are successfully retrieved the socket enters
ConnectingState, and attempts to connect to \a address. If a connection is established,
QBluetoothSocket enters Connected State and emits connected().
On BlackBerry and Android, the service connection can directly be established
using the UUID of the remote service. Therefore these platforms do not require
the \l ServiceLookupState and \l socketType() is always set to
\l QBluetoothServiceInfo::RfcommProtocol.
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 QBluetoothAddress &address, const QBluetoothUuid &uuid, OpenMode openMode)
{
Q_D(QBluetoothSocket);
if (state() != QBluetoothSocket::UnconnectedState) {
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(QBluetoothServiceInfo::RfcommProtocol)) {
d->errorString = tr("Socket type not supported");
setSocketError(QBluetoothSocket::UnsupportedProtocolError);
return;
}
d->connectToService(address, uuid, openMode);
#else
QBluetoothServiceInfo service;
QBluetoothDeviceInfo device(address, QString(), QBluetoothDeviceInfo::MiscellaneousDevice);
service.setDevice(device);
service.setServiceUuid(uuid);
doDeviceDiscovery(service, openMode);
#endif
}
示例2: QBluetoothAddress
static PyObject *meth_QBluetoothServiceInfo_registerService(PyObject *sipSelf, PyObject *sipArgs, PyObject *sipKwds)
{
PyObject *sipParseErr = NULL;
{
const QBluetoothAddress& a0def = QBluetoothAddress();
const QBluetoothAddress* a0 = &a0def;
QBluetoothServiceInfo *sipCpp;
static const char *sipKwdList[] = {
sipName_localAdapter,
};
if (sipParseKwdArgs(&sipParseErr, sipArgs, sipKwds, sipKwdList, NULL, "B|J9", &sipSelf, sipType_QBluetoothServiceInfo, &sipCpp, sipType_QBluetoothAddress, &a0))
{
bool sipRes;
sipRes = sipCpp->registerService(*a0);
return PyBool_FromLong(sipRes);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QBluetoothServiceInfo, sipName_registerService, doc_QBluetoothServiceInfo_registerService);
return NULL;
}
示例3: Q_D
void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, OpenMode openMode)
{
Q_D(QBluetoothSocket);
setSocketState(QBluetoothSocket::ServiceLookupState);
qCDebug(QT_BT) << "Starting discovery";
if(d->discoveryAgent) {
d->discoveryAgent->stop();
delete d->discoveryAgent;
}
d->discoveryAgent = new QBluetoothServiceDiscoveryAgent(this);
d->discoveryAgent->setRemoteAddress(service.device().address());
//qDebug() << "Got agent";
connect(d->discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
connect(d->discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished()));
d->openMode = openMode;
if(!service.serviceUuid().isNull())
d->discoveryAgent->setUuidFilter(service.serviceUuid());
if(!service.serviceClassUuids().isEmpty())
d->discoveryAgent->setUuidFilter(service.serviceClassUuids());
// we have to ID the service somehow
Q_ASSERT(!d->discoveryAgent->uuidFilter().isEmpty());
qCDebug(QT_BT) << "UUID filter" << d->discoveryAgent->uuidFilter();
d->discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
}
示例4: QBluetoothAddress
//! [Connect to remote service]
void Chat::connectClicked()
{
ui->connectButton->setEnabled(false);
// scan for services
const QBluetoothAddress adapter = localAdapters.isEmpty() ?
QBluetoothAddress() :
localAdapters.at(currentAdapterIndex).address();
RemoteSelector remoteSelector(adapter);
remoteSelector.startDiscovery(QBluetoothUuid(serviceUuid));
if (remoteSelector.exec() == QDialog::Accepted) {
QBluetoothServiceInfo service = remoteSelector.service();
qDebug() << "Connecting to service 2" << service.serviceName()
<< "on" << service.device().name();
// Create client
qDebug() << "Going to create client";
ChatClient *client = new ChatClient(this);
qDebug() << "Connecting...";
connect(client, SIGNAL(messageReceived(QString,QString)),
this, SLOT(showMessage(QString,QString)));
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
connect(client, SIGNAL(connected(QString)), this, SLOT(connected(QString)));
connect(this, SIGNAL(sendMessage(QString)), client, SLOT(sendMessage(QString)));
qDebug() << "Start client";
client->startClient(service);
clients.append(client);
}
ui->connectButton->setEnabled(true);
}
示例5: serviceDiscovered
void Tennis::serviceDiscovered(const QBluetoothServiceInfo &serviceInfo)
{
qDebug() << "***** Discovered! " << serviceInfo.device().name() << serviceInfo.serviceName() << serviceInfo.serviceUuid();
qDebug() << "Found one!" << serviceInfo.protocolServiceMultiplexer();
m_discoveryAgent->stop();
client->startClient(serviceInfo);
QSettings settings("QtDF", "bttennis");
settings.setValue("lastclient", serviceInfo.device().address().toString());
}
示例6: foreach
void BtLocalDevice::serviceDiscovered(const QBluetoothServiceInfo &info)
{
QStringList classIds;
foreach (const QBluetoothUuid &uuid, info.serviceClassUuids())
classIds.append(uuid.toString());
qDebug() << "$$ Found new service" << info.device().address().toString()
<< info.serviceUuid() << info.serviceName() << info.serviceDescription() << classIds;
if (info.serviceUuid() == QBluetoothUuid(QString(TEST_SERVICE_UUID))
|| info.serviceClassUuids().contains(QBluetoothUuid(QString(TEST_SERVICE_UUID))))
{
//This is here to detect the test server for SPP testing later on
bool alreadyKnown = false;
foreach (const QBluetoothServiceInfo& found, foundTestServers) {
if (found.device().address() == info.device().address()) {
alreadyKnown = true;
break;
}
}
if (!alreadyKnown) {
foundTestServers.append(info);
qDebug() << "@@@@@@@@ Adding:" << info.device().address().toString();
}
}
示例7: serviceDiscovered
void QBluetoothSocket::serviceDiscovered(const QBluetoothServiceInfo &service)
{
Q_D(QBluetoothSocket);
qCDebug(QT_BT) << "FOUND SERVICE!" << service;
if (service.protocolServiceMultiplexer() > 0 || service.serverChannel() > 0) {
connectToService(service, d->openMode);
d->discoveryAgent->deleteLater();
d->discoveryAgent = 0;
} else {
qCDebug(QT_BT) << "Could not find port/psm for potential remote service";
}
}
示例8: pairingFinished
void RemoteSelector::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing status)
{
QBluetoothServiceInfo service;
int row = 0;
ui->pairingBusy->hide();
ui->pairingBusy->movie()->stop();
ui->remoteDevices->blockSignals(true);
for(int i = 0; i < m_discoveredServices.count(); i++){
if(m_discoveredServices.value(i).device().address() == address){
service = m_discoveredServices.value(i);
row = i;
break;
}
}
if(m_pindisplay)
delete m_pindisplay;
QMessageBox msgBox;
if(status == QBluetoothLocalDevice::Paired ||
status == QBluetoothLocalDevice::AuthorizedPaired){
msgBox.setText("Paired successfully with" + address.toString());
}
else {
msgBox.setText("Pairing failed with " + address.toString());
}
if(service.isValid()){
if(status == QBluetoothLocalDevice::AuthorizedPaired){
ui->remoteDevices->item(row, 3)->setCheckState(Qt::Checked);
ui->remoteDevices->item(row, 4)->setCheckState(Qt::Checked);
}
else if(status == QBluetoothLocalDevice::Paired){
ui->remoteDevices->item(row, 3)->setCheckState(Qt::Checked);
ui->remoteDevices->item(row, 4)->setCheckState(Qt::Unchecked);
}
else {
ui->remoteDevices->item(row, 3)->setCheckState(Qt::Unchecked);
ui->remoteDevices->item(row, 4)->setCheckState(Qt::Unchecked);
}
}
msgBox.exec();
ui->remoteDevices->blockSignals(false);
}
示例9: isDuplicatedService
bool QBluetoothServiceDiscoveryAgentPrivate::isDuplicatedService(
const QBluetoothServiceInfo &serviceInfo) const
{
//check the service is not already part of our known list
for (int j = 0; j < discoveredServices.count(); j++) {
const QBluetoothServiceInfo &info = discoveredServices.at(j);
if (info.device() == serviceInfo.device()
&& info.serviceClassUuids() == serviceInfo.serviceClassUuids()
&& info.serviceUuid() == serviceInfo.serviceUuid()) {
return true;
}
}
return false;
}
示例10: socketType
/*!
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
}
示例11: qWarning
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();
}
示例12: QCOMPARE
void tst_QBluetoothServiceInfo::tst_serviceClassUuids()
{
QBluetoothServiceInfo info;
QCOMPARE(info.serviceClassUuids().count(), 0);
QBluetoothServiceInfo::Sequence classIds;
classIds << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
QCOMPARE(classIds.count(), 1);
QBluetoothUuid uuid(QString("e8e10f95-1a70-4b27-9ccf-02010264e9c8"));
classIds.prepend(QVariant::fromValue(uuid));
QCOMPARE(classIds.count(), 2);
QCOMPARE(classIds.at(0).value<QBluetoothUuid>(), uuid);
info.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classIds);
QList<QBluetoothUuid> svclids = info.serviceClassUuids();
QCOMPARE(svclids.count(), 2);
QCOMPARE(svclids.at(0), uuid);
QCOMPARE(svclids.at(1), QBluetoothUuid(QBluetoothUuid::SerialPort));
}
示例13: Py_INCREF
static PyObject *meth_QBluetoothServiceInfo_setServiceAvailability(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
quint8 a0;
QBluetoothServiceInfo *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BM", &sipSelf, sipType_QBluetoothServiceInfo, &sipCpp, &a0))
{
sipCpp->setServiceAvailability(a0);
Py_INCREF(Py_None);
return Py_None;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QBluetoothServiceInfo, sipName_setServiceAvailability, doc_QBluetoothServiceInfo_setServiceAvailability);
return NULL;
}
示例14: qDebug
void Tennis::nearFieldHandover()
{
qDebug() << "Connecting to NFC provided address" << m_handover->bluetoothAddress().toString();
QBluetoothDeviceInfo device = QBluetoothDeviceInfo(m_handover->bluetoothAddress(), QString(),
QBluetoothDeviceInfo::ComputerDevice);
QBluetoothServiceInfo service;
service.setServiceUuid(QBluetoothUuid(serviceUuid));
service.setDevice(device);
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap))
<< QVariant::fromValue(m_handover->serverPort());
protocolDescriptorList.append(QVariant::fromValue(protocol));
service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
protocolDescriptorList);
client->startClient(service);
board->setStatus(tr("Connecting: %1 %2").arg(m_handover->bluetoothAddress().toString()).arg(m_handover->serverPort()), 100, 25);
}
示例15: PyBool_FromLong
static PyObject *meth_QBluetoothServiceInfo_unregisterService(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
QBluetoothServiceInfo *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QBluetoothServiceInfo, &sipCpp))
{
bool sipRes;
sipRes = sipCpp->unregisterService();
return PyBool_FromLong(sipRes);
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QBluetoothServiceInfo, sipName_unregisterService, doc_QBluetoothServiceInfo_unregisterService);
return NULL;
}