本文整理汇总了C++中QBluetoothLocalDevice类的典型用法代码示例。如果您正苦于以下问题:C++ QBluetoothLocalDevice类的具体用法?C++ QBluetoothLocalDevice怎么用?C++ QBluetoothLocalDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QBluetoothLocalDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QFETCH
void tst_QBluetoothLocalDevice::tst_pairDevice()
{
QFETCH(QBluetoothAddress, deviceAddress);
QFETCH(QBluetoothLocalDevice::Pairing, pairingExpected);
QBluetoothLocalDevice localDevice;
//powerOn if not already
localDevice.powerOn();
QSignalSpy pairingSpy(&localDevice, SIGNAL(pairingFinished(const QBluetoothAddress &,QBluetoothLocalDevice::Pairing)) );
// there should be no signals yet
QVERIFY(pairingSpy.isEmpty());
localDevice.requestPairing(deviceAddress, pairingExpected);
// async, wait for it
WAIT_FOR_CONDITION(pairingSpy.count(),1);
QVERIFY(pairingSpy.count() > 0);
// test the actual signal values.
QList<QVariant> arguments = pairingSpy.takeFirst();
QBluetoothAddress address = qvariant_cast<QBluetoothAddress>(arguments.at(0));
QBluetoothLocalDevice::Pairing pairingResult = qvariant_cast<QBluetoothLocalDevice::Pairing>(arguments.at(1));
QCOMPARE(deviceAddress, address);
QCOMPARE(pairingExpected, pairingResult);
QCOMPARE(pairingExpected, localDevice.pairingStatus(deviceAddress));
}
示例2: QBluetoothLocalDevice
void tst_QBluetoothTransferRequest::initTestCase()
{
// start Bluetooth if not started
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
device->powerOn();
delete device;
}
示例3: MdAbstractCom
MdBluetoothCom::MdBluetoothCom(QObject *parent, QString mdServiceName)
: MdAbstractCom(parent), sDiscoveryAgent (0), socket (0), sdNeeded(Yes), mdServiceName(mdServiceName)
{
QBluetoothLocalDevice localDevice;
// Check if Bluetooth is available on this device
if (localDevice.isValid()) {
// Turn Bluetooth on
localDevice.powerOn();
// Read local device name
localDeviceName = localDevice.name();
qDebug() << "local bluetooth device name: " << localDeviceName;
// Make it visible to others
//localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
// Get connected devices
remotes = localDevice.connectedDevices();
startServiceDiscovery();
} else {
qDebug() << "bluetooth not available!";
emit showStatusMessage( "Bluetooth: not available!" );
}
}
示例4: QFETCH
void tst_QBluetoothLocalDevice::tst_pairDevice()
{
QFETCH(QBluetoothAddress, deviceAddress);
QFETCH(QBluetoothLocalDevice::Pairing, pairingExpected);
if (!QBluetoothLocalDevice::allDevices().count())
QSKIP("Skipping test due to missing Bluetooth device");
qDebug() << "tst_pairDevice(): address=" << deviceAddress.toString() << "pairingModeExpected="
<< static_cast<int>(pairingExpected);
QBluetoothLocalDevice localDevice;
//powerOn if not already
localDevice.powerOn();
QSignalSpy pairingSpy(&localDevice, SIGNAL(pairingFinished(const QBluetoothAddress &,QBluetoothLocalDevice::Pairing)) );
// there should be no signals yet
QVERIFY(pairingSpy.isValid());
QVERIFY(pairingSpy.isEmpty());
QVERIFY(localDevice.isValid());
localDevice.requestPairing(deviceAddress, pairingExpected);
// async, wait for it
QTRY_VERIFY(pairingSpy.count() > 0);
// test the actual signal values.
QList<QVariant> arguments = pairingSpy.takeFirst();
QBluetoothAddress address = qvariant_cast<QBluetoothAddress>(arguments.at(0));
QBluetoothLocalDevice::Pairing pairingResult = qvariant_cast<QBluetoothLocalDevice::Pairing>(arguments.at(1));
QCOMPARE(deviceAddress, address);
QCOMPARE(pairingExpected, pairingResult);
QCOMPARE(pairingExpected, localDevice.pairingStatus(deviceAddress));
}
示例5: QSKIP
void tst_QBluetoothLocalDevice::tst_powerOff()
{
if (!QBluetoothLocalDevice::allDevices().count())
QSKIP("Skipping test due to missing Bluetooth device");
{
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
device->powerOn();
delete device;
// wait for the device to switch bluetooth mode.
QTest::qWait(1000);
}
QBluetoothLocalDevice localDevice;
QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)));
// there should be no changes yet
QVERIFY(hostModeSpy.isValid());
QVERIFY(hostModeSpy.isEmpty());
localDevice.setHostMode(QBluetoothLocalDevice::HostPoweredOff);
// async, wait for it
QTRY_VERIFY(hostModeSpy.count() > 0);
// we should not be powered off
QVERIFY(localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff);
}
示例6: QDialog
ServiceDiscoveryDialog::ServiceDiscoveryDialog(const QString &name,
const QBluetoothAddress &address, QWidget *parent)
: QDialog(parent), ui(new Ui_ServiceDiscovery)
{
ui->setupUi(this);
//Using default Bluetooth adapter
QBluetoothLocalDevice localDevice;
QBluetoothAddress adapterAddress = localDevice.address();
/*
* In case of multiple Bluetooth adapters it is possible to
* set which adapter will be used by providing MAC Address.
* Example code:
*
* QBluetoothAddress adapterAddress("XX:XX:XX:XX:XX:XX");
* discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress);
*/
discoveryAgent = new QBluetoothServiceDiscoveryAgent(adapterAddress);
discoveryAgent->setRemoteAddress(address);
setWindowTitle(name);
connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
this, SLOT(addService(QBluetoothServiceInfo)));
connect(discoveryAgent, SIGNAL(finished()), ui->status, SLOT(hide()));
discoveryAgent->start();
}
示例7: sendBluetoothService
void Handover::sendBluetoothService()
{
QBluetoothLocalDevice localDevice;
const QString data = localDevice.address().toString() + QLatin1Char(' ') +
QString::number(m_localServerPort);
m_remote->write(data.toUtf8());
}
示例8: QBluetoothLocalDevice
void tst_QBluetoothDeviceInfo::initTestCase()
{
qRegisterMetaType<QBluetoothDeviceInfo::ServiceClasses>("QBluetoothDeviceInfo::ServiceClasses");
qRegisterMetaType<QBluetoothDeviceInfo::MajorDeviceClass>("QBluetoothDeviceInfo::MajorDeviceClass");
// start Bluetooth if not started
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
device->powerOn();
delete device;
}
示例9: QVERIFY
void tst_QBluetoothLocalDevice::tst_construction()
{
QBluetoothLocalDevice localDevice;
QVERIFY(localDevice.isValid());
QBluetoothLocalDevice anotherDevice = new QBluetoothLocalDevice(QBluetoothAddress(000000000000));
QVERIFY(anotherDevice.isValid());
QVERIFY(anotherDevice.address().toUInt64() != 0);
}
示例10: QBluetoothLocalDevice
tst_QBluetoothLocalDevice::tst_QBluetoothLocalDevice()
{
// start with host powered off
QBluetoothLocalDevice *device = new QBluetoothLocalDevice();
device->setHostMode(QBluetoothLocalDevice::HostPoweredOff);
delete device;
// wait for the device to switch bluetooth mode.
QTest::qWait(1000);
}
示例11: QVERIFY
void tst_QBluetoothLocalDevice::tst_isValid()
{
QBluetoothLocalDevice localDevice;
QVERIFY(localDevice.isValid());
/*
//TODO the above should really be the following once QBluetoothLocalDevice has been fixed
if (!QBluetoothLocalDevice::allDevices().count())
QVERIFY(!localDevice.isValid());
else
QVERIFY(localDevice.isValid());
*/
}
示例12: qLog
/*!
\internal
*/
void QBluetoothHeadsetService::newConnection()
{
qLog(Bluetooth) << "QBluetoothHeadsetService::New client has connected.";
// New client has connected
QBluetoothRfcommSocket *socket =
static_cast<QBluetoothRfcommSocket *>(m_data->m_server->nextPendingConnection());
qLog(Bluetooth) << "Socket is:" << socket->socketDescriptor();
if (m_data->m_client &&
(m_data->m_connectInProgress ||
(m_data->m_client->state() == QBluetoothRfcommSocket::ConnectedState))) {
qLog(Bluetooth) << "Already connected, closing client socket.";
socket->close();
delete socket;
return;
}
hookupSocket(socket);
m_data->m_interface->setValue("IsConnected", true);
qLog(Bluetooth) << "Starting Bluetooth session for Headset";
if (!m_data->m_session) {
qLog(Bluetooth) << "Lazy initializing the QCommDeviceSession object";
QBluetoothLocalDevice local;
m_data->m_session = new QCommDeviceSession(local.deviceName().toLatin1());
QObject::connect(m_data->m_session, SIGNAL(sessionOpen()), this, SLOT(sessionOpen()));
QObject::connect(m_data->m_session, SIGNAL(sessionFailed()), this, SLOT(sessionFailed()));
}
m_data->m_session->startSession();
qLog(Bluetooth) << "The socket remoteAddress is:" << socket->remoteAddress().toString();
m_data->m_interface->setValue("RemotePeer",
QVariant::fromValue(socket->remoteAddress()));
emit newConnection(socket->remoteAddress());
qLog(Bluetooth) << "The socket has bytesAvailable:" << socket->bytesAvailable();
if (socket->bytesAvailable()) {
readyRead();
}
}
示例13: QBluetoothAddress
void Handover::readBluetoothService()
{
QByteArray rawData = m_client->readAll();
QString data = QString::fromUtf8(rawData.constData(), rawData.size());
QStringList split = data.split(QLatin1Char(' '));
QBluetoothAddress address = QBluetoothAddress(split.at(0));
quint16 port = split.at(1).toUInt();
QBluetoothLocalDevice localDevice;
QBluetoothAddress localAddress = localDevice.address();
if (localAddress < address) {
m_address = address;
m_serverPort = port;
emit bluetoothServiceChanged();
}
}
示例14: hostModeSpy
void tst_QBluetoothLocalDevice::tst_powerOn()
{
{
QBluetoothLocalDevice localDevice;
QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)));
// there should be no changes yet
QVERIFY(hostModeSpy.isEmpty());
localDevice.powerOn();
// async, wait for it
WAIT_FOR_CONDITION(hostModeSpy.count(),1);
QVERIFY(hostModeSpy.count() > 0);
QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode();
// we should not be powered off
QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable
|| hostMode == QBluetoothLocalDevice::HostDiscoverable);
}
}
示例15: hostModeSpy
void tst_QBluetoothLocalDevice::tst_powerOn()
{
QBluetoothLocalDevice localDevice;
QSignalSpy hostModeSpy(&localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)));
// there should be no changes yet
QVERIFY(hostModeSpy.isValid());
QVERIFY(hostModeSpy.isEmpty());
if (!QBluetoothLocalDevice::allDevices().count())
QSKIP("Skipping test due to missing Bluetooth device");
localDevice.powerOn();
// async, wait for it
QTRY_VERIFY(hostModeSpy.count() > 0);
QBluetoothLocalDevice::HostMode hostMode= localDevice.hostMode();
// we should not be powered off
QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable
|| hostMode == QBluetoothLocalDevice::HostDiscoverable);
}