void tst_QBluetoothTransferRequest::initTestCase() { // start Bluetooth if not started QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; }
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!" ); } }
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)); }
void MyClass::localDevice() { //! [turningon] QBluetoothLocalDevice localDevice; QString localDeviceName; // Check if Bluetooth is available on this device if (localDevice.isValid()) { // Turn Bluetooth on localDevice.powerOn(); // Read local device name localDeviceName = localDevice.name(); // Make it visible to others localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable); // Get connected devices QList<QBluetoothAddress> remotes; remotes = localDevice.connectedDevices(); } //! [turningon] }
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)); }
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); }
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; }
void tst_QBluetoothServiceInfo::initTestCase() { qRegisterMetaType<QBluetoothUuid::ProtocolUuid>("QBluetoothUuid::ProtocolUuid"); qRegisterMetaType<QUuid>("QUuid"); qRegisterMetaType<QBluetoothServiceInfo::Protocol>("QBluetoothServiceInfo::Protocol"); // start Bluetooth if not started QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; }
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); } }
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); }
void tst_QBluetoothLocalDevice::tst_powerOff() { { 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.isEmpty()); localDevice.setHostMode(QBluetoothLocalDevice::HostPoweredOff); // async, wait for it WAIT_FOR_CONDITION(hostModeSpy.count(),1); QVERIFY(hostModeSpy.count() > 0); // we should not be powered off QVERIFY(localDevice.hostMode() == QBluetoothLocalDevice::HostPoweredOff); }
void tst_QBluetoothDeviceDiscoveryAgent::initTestCase() { qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo"); qRegisterMetaType<QBluetoothDeviceDiscoveryAgent::InquiryType>("QBluetoothDeviceDiscoveryAgent::InquiryType"); // turn on BT in case it is not on QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); if (device->hostMode() == QBluetoothLocalDevice::HostPoweredOff) { QSignalSpy hostModeSpy(device, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode))); QVERIFY(hostModeSpy.isEmpty()); device->powerOn(); int connectTime = 5000; // ms while (hostModeSpy.count() < 1 && connectTime > 0) { QTest::qWait(500); connectTime -= 500; } QVERIFY(hostModeSpy.count() > 0); } QBluetoothLocalDevice::HostMode hostMode= device->hostMode(); QVERIFY(hostMode == QBluetoothLocalDevice::HostConnectable || hostMode == QBluetoothLocalDevice::HostDiscoverable || hostMode == QBluetoothLocalDevice::HostDiscoverableLimitedInquiry); delete device; }
Tennis::Tennis(QWidget *parent) : QDialog(parent), ui(new Ui_Tennis), board(new Board), controller(new Controller), socket(0), m_discoveryAgent(new QBluetoothServiceDiscoveryAgent), m_handover(0) { // start Bluetooth if not started QBluetoothLocalDevice *device = new QBluetoothLocalDevice(); device->powerOn(); delete device; device = 0; //! [Construct UI] ui->setupUi(this); isClient = false; isConnected = false; quickDiscovery = true; #if defined (Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) setWindowState(Qt::WindowMaximized); #endif ui->pongView->setScene(board->getScene()); connect(ui->pongView, SIGNAL(mouseMove(int, int)), this, SLOT(mouseMove(int, int))); ui->pongView->setMouseTracking(false); connect(board, SIGNAL(ballCollision(Board::Edge)), controller, SLOT(ballCollision(Board::Edge))); connect(board, SIGNAL(scored(Board::Edge)), controller, SLOT(scored(Board::Edge))); connect(controller, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(controller, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(controller, SIGNAL(fps(const QString&)), this, SLOT(fps(const QString&))); setFocusPolicy(Qt::WheelFocus); paddle_pos = (Board::Height-12)/2-Board::Paddle/2; endPaddlePos = paddle_pos; emit moveLeftPaddle(paddle_pos); board->setRightPaddle(paddle_pos); server = new TennisServer(this); connect(controller, SIGNAL(moveBall(int,int)), server, SLOT(moveBall(int,int))); connect(controller, SIGNAL(score(int,int)), server, SLOT(score(int,int))); connect(this, SIGNAL(moveLeftPaddle(int)), server, SLOT(moveLeftPaddle(int))); connect(server, SIGNAL(clientConnected(QString)), this, SLOT(serverConnected(QString))); connect(server, SIGNAL(clientDisconnected(QString)), this, SLOT(serverDisconnected())); connect(server, SIGNAL(moveRightPaddle(int)), board, SLOT(setRightPaddle(int))); connect(server, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(server, SIGNAL(clientConnected(QString)), controller, SLOT(refresh())); server->startServer(); client = new TennisClient(this); connect(client, SIGNAL(moveBall(int,int)), board, SLOT(setBall(int,int))); connect(client, SIGNAL(moveLeftPaddle(int)), board, SLOT(setLeftPaddle(int))); connect(client, SIGNAL(connected(QString)), this, SLOT(clientConnected(QString))); connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(this, SIGNAL(moveRightPaddle(int)), client, SLOT(moveRightPaddle(int))); connect(client, SIGNAL(score(int,int)), board, SLOT(setScore(int,int))); connect(client, SIGNAL(lag(int)), this, SLOT(lagReport(int))); connect(this, SIGNAL(moveLeftPaddle(int)), controller, SLOT(moveLeftPaddle(int))); connect(this, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); connect(server, SIGNAL(moveRightPaddle(int)), controller, SLOT(moveRightPaddle(int))); // ui->pongView->setBackgroundBrush(QBrush(Qt::white)); ui->pongView->setCacheMode(QGraphicsView::CacheBackground); QNearFieldManager nearFieldManager; if (nearFieldManager.isAvailable()) { m_handover = new Handover(server->serverPort(), this); connect(m_handover, SIGNAL(bluetoothServiceChanged()), this, SLOT(nearFieldHandover())); connect(m_discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); connect(m_discoveryAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); } m_discoveryAgent->setUuidFilter(QBluetoothUuid(serviceUuid)); QString address; QString port; QStringList args = QCoreApplication::arguments(); if(args.length() >= 2){ address = args.at(1); if(args.length() >= 3){ port = args.at(2); } } if(address.isEmpty()){ QSettings settings("QtDF", "bttennis"); address = settings.value("lastclient").toString(); } if(!address.isEmpty()){ qDebug() << "Connect to" << address << port; QBluetoothDeviceInfo device = QBluetoothDeviceInfo(QBluetoothAddress(address), "", QBluetoothDeviceInfo::ComputerDevice); QBluetoothServiceInfo service; if (!port.isEmpty()) { QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(port.toUShort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); service.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); qDebug() << "port" << port.toUShort() << service.protocolServiceMultiplexer(); } else { service.setServiceUuid(QBluetoothUuid(serviceUuid)); } service.setDevice(device); client->startClient(service); board->setStatus("Connecting", 100, 25); } else if (nearFieldManager.isAvailable()) { board->setStatus(tr("Touch to play"), 100, 25); } setEnabled(true); paddleAnimation = new QPropertyAnimation(this, "paddlePos", this); paddleAnimation->setEasingCurve(QEasingCurve::InOutQuad); ui->pongView->installEventFilter(this); }