(同じ利用者による、間の7版が非表示)
144行目: 144行目:
* AD Data (可変長)
* AD Data (可変長)
<br>
<br>
[[ファイル:Qt BLE 3.png|フレームなし|中央]]
<br>
==== その他 (通信特性 / セキュリティ等) ====
==== その他 (通信特性 / セキュリティ等) ====
* 通信特性
* 通信特性
526行目: 529行目:
<br>
<br>
==== 使用例 ====
==== 使用例 ====
===== QLowEnergyControllerクラスのインスタンスの生成 =====
まず、<code>QBluetoothDeviceDiscoveryAgent</code>クラスを使用して、スキャンを実行する。<br>
<br>
次に、接続するデバイスの<code>QBluetoothDeviceInfo</code>クラスのデバイス情報を取得する。<br>
取得したデバイス情報を元に、<code>QLowEnergyController</code>クラスのインスタンスを生成する。<br>
<br>
===== コントローラのシグナル / スロット接続 =====
最低限必要なシグナルを示す。<br>
* connected
*: デバイスへの接続完了を通知
* disconnected
*: デバイスとの切断を通知 
* serviceDiscovered
*: 新しいサービスの発見を通知
* discoveryFinished
*: サービス探索の完了を通知
<br>
===== BLEデバイスの接続 =====
connectToDeviceメソッドを実行してBLEデバイスに接続する。<br>
connectedシグナルの受信を待つ。<br>
<br>
===== サービスの探索 =====
BLEデバイスへ接続後、discoverServicesメソッドを実行してサービスの探索を開始する。<br>
<br>
* serviceDiscoveredシグナルで個々のサービスが見つかる度に通知される。
* discoveryFinishedシグナルで探索完了が通知される。
<br>
===== サービスの取得 =====
createServiceObjectメソッドをを実行して、探索で発見したサービスのQLowEnergyServiceオブジェクトを生成する。<br>
このオブジェクトを使用して、特性 (Characteristic) や ディスクリプタにアクセスできる。<br>
<br>
===== 組み合わせ =====
  <syntaxhighlight lang="c++">
  <syntaxhighlight lang="c++">
// BLEのサービス探索を管理するクラス
// BLEデバイスへの接続, サービスの探索と監視
  #include <QObject>
  #include <QObject>
  #include <QLowEnergyController>
  #include <QLowEnergyController>
  #include <QLowEnergyService>
  #include <QLowEnergyService>
  #include <QTimer>
  #include <QTimer>
#include <memory>
  #include <QDebug>
  #include <QDebug>
   
   
539行目: 576行目:
   
   
  private:
  private:
     std::unique_ptr<QLowEnergyController> controller;
     QLowEnergyController controller;       // BLE接続とサービス探索を制御するコントローラ
     std::unique_ptr<QTimer>               discoveryTimeout;
     QTimer              discoveryTimeout; // サービス探索のタイムアウトを管理するタイマ
   
   
    // コントローラの各種シグナルを接続
    // 接続 / 切断, サービス探索の進行状況, 状態変更, エラー
     void connectControllerSignals()
     void connectControllerSignals()
     {
     {
       connect(controller.get(), &QLowEnergyController::connected, this, &BLEServiceDiscovery::onConnected);
       connect(&controller, &QLowEnergyController::connected, this, &BLEServiceDiscovery::onConnected);
       connect(controller.get(), &QLowEnergyController::disconnected, this, &BLEServiceDiscovery::onDisconnected);
       connect(&controller, &QLowEnergyController::disconnected, this, &BLEServiceDiscovery::onDisconnected);
       connect(controller.get(), &QLowEnergyController::serviceDiscovered, this, &BLEServiceDiscovery::onServiceDiscovered);
       connect(&controller, &QLowEnergyController::serviceDiscovered, this, &BLEServiceDiscovery::onServiceDiscovered);
       connect(controller.get(), &QLowEnergyController::discoveryFinished, this, &BLEServiceDiscovery::onDiscoveryFinished);
       connect(&controller, &QLowEnergyController::discoveryFinished, this, &BLEServiceDiscovery::onDiscoveryFinished);
       connect(controller.get(), static_cast<void(QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error), this, &BLEServiceDiscovery::onError);
       connect(&controller, static_cast<void(QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error), this, &BLEServiceDiscovery::onError);
       connect(controller.get(), &QLowEnergyController::stateChanged, this, &BLEServiceDiscovery::onStateChanged);
       connect(&controller, &QLowEnergyController::stateChanged, this, &BLEServiceDiscovery::onStateChanged);
     }
     }
   
   
    // 個別のBLEサービスに対するシグナル
    // 状態変更とエラーイベントを監視してログを出力する
     void connectServiceSignals(QLowEnergyService *service)
     void connectServiceSignals(QLowEnergyService *service)
     {
     {
563行目: 604行目:
     }
     }
   
   
    // エラーコードの変換
     QString getErrorMessage(QLowEnergyController::Error error)
     QString getErrorMessage(QLowEnergyController::Error error)
     {
     {
619行目: 661行目:
     {
     {
       // タイムアウトタイマの初期化
       // タイムアウトタイマの初期化
       discoveryTimeout = std::make_unique<QTimer>(this);
       discoveryTimeout.setInterval(10000);  // 10秒のタイムアウト
      discoveryTimeout->setInterval(10000);  // 10秒のタイムアウト
       discoveryTimeout.setSingleShot(true);
       discoveryTimeout->setSingleShot(true);
   
   
       connect(discoveryTimeout.get(), &QTimer::timeout, this, &BLEServiceDiscovery::onDiscoveryTimeout);
       connect(&discoveryTimeout, &QTimer::timeout, this, &BLEServiceDiscovery::onDiscoveryTimeout);
     }
     }
   
   
     // デバイスへの接続とサービス探索の開始
     // デバイスへの接続とサービス探索の開始
     void startDiscovery(const QBluetoothDeviceInfo& device)
    // コントローラの初期化, シグナルの接続, デバイスへの接続開始, タイムアウトタイマの開始
     void startDiscovery(const QBluetoothDeviceInfo &device)
     {
     {
       try {
       try {
633行目: 675行目:
   
   
           // コントローラの初期化
           // コントローラの初期化
          controller = std::make_unique<QLowEnergyController>(device, this);
           connectControllerSignals();
           connectControllerSignals();
   
   
           // 接続開始
           // 接続開始
           controller->connectToDevice();
           controller.connectToDevice();
           discoveryTimeout->start();
           discoveryTimeout.start();
       }
       }
       catch (const std::exception &e) {
       catch (const std::exception &e) {
647行目: 688行目:
     }
     }
   
   
     // 探索を停止
     // 探索を停止 (タイムアウトタイマも停止)
     void stopDiscovery()
     void stopDiscovery()
     {
     {
       try {
       try {
           if (controller) {
           if (controller) {
             controller->disconnectFromDevice();
             controller.disconnectFromDevice();
             discoveryTimeout->stop();
             discoveryTimeout.stop();
           }
           }
       }
       }
664行目: 705行目:
   
   
  signals:
  signals:
     void serviceDiscovered(QLowEnergyService *service);
     void serviceDiscovered(QLowEnergyService *service); // 新しいサービスが発見された時に発行
     void discoveryComplete();
     void discoveryComplete();                           // 全てのサービス探索が完了した時に発行
     void errorOccurred(const QString &error);
     void errorOccurred(const QString &error);           // エラーが発生した時に発行
     void connectionStateChanged(QLowEnergyController::ControllerState state);
     void connectionStateChanged(QLowEnergyController::ControllerState state); // 接続状態が変更された時に発行
   
   
  private slots:
  private slots:
    // デバイスへの接続が完了した時 (タイムアウトタイマを停止して、サービス探索を開始)
     void onConnected()
     void onConnected()
     {
     {
       qDebug() << "デバイスに接続";
       qDebug() << "デバイスに接続";
       discoveryTimeout->stop();
       discoveryTimeout.stop();
   
   
       // サービス探索の開始
       // サービス探索の開始
       controller->discoverServices();
       controller.discoverServices();
     }
     }
   
   
    // デバイスから切断された時 (タイムアウトタイマを停止)
     void onDisconnected()
     void onDisconnected()
     {
     {
       qDebug() << "デバイスから切断";
       qDebug() << "デバイスから切断";
       discoveryTimeout->stop();
       discoveryTimeout.stop();
     }
     }
   
   
    // 新しいサービスが発見された時
     void onServiceDiscovered(const QBluetoothUuid& uuid)
     void onServiceDiscovered(const QBluetoothUuid& uuid)
     {
     {
690行目: 734行目:
   
   
       // サービスオブジェクトの作成
       // サービスオブジェクトの作成
       QLowEnergyService* service = controller->createServiceObject(uuid, this);
       QLowEnergyService* service = controller.createServiceObject(uuid, this);
       if (service) {
       if (service) {
           connectServiceSignals(service);
           connectServiceSignals(service);
697行目: 741行目:
     }
     }
   
   
    // サービス探索が完了した時
     void onDiscoveryFinished()
     void onDiscoveryFinished()
     {
     {
       qDebug() << "サービス探索が完了";
       qDebug() << "サービス探索が完了";
       discoveryTimeout->stop();
       discoveryTimeout.stop();
       emit discoveryComplete();
       emit discoveryComplete();
     }
     }
   
   
    // エラーが発生した時
     void onError(QLowEnergyController::Error error)
     void onError(QLowEnergyController::Error error)
     {
     {
711行目: 757行目:
     }
     }
   
   
    // タイムアウトが発生した時 (探索を停止して、エラーとして通知)
     void onDiscoveryTimeout()
     void onDiscoveryTimeout()
     {
     {
718行目: 765行目:
     }
     }
   
   
    // 接続状態が変更された時 (状態の変更をログ出力して、通知)
     void onStateChanged(QLowEnergyController::ControllerState state)
     void onStateChanged(QLowEnergyController::ControllerState state)
     {
     {
792行目: 840行目:
<br>
<br>
==== 使用例 ====
==== 使用例 ====
===== ローカルデバイスの初期化 =====
BLEデバイスを利用するため、QBluetoothLocalDeviceクラスを使用して初期化する。<br>
初期化時にBLEデバイスが有効かどうかの確認を行う。<br>
<br>
* QBluetoothLocalDeviceクラス
* QBluetoothAddressクラス
<br>
  <syntaxhighlight lang="c++">
  <syntaxhighlight lang="c++">
#include <QBluetoothLocalDevice>
#include <QBluetoothAddress>
QBluetoothLocalDevice localDevice;
if (!localDevice.isValid()) {
    qDebug() << "Bluetoothデバイスが利用できません";
    return;
}
</syntaxhighlight>
<br>
===== ペアリング状態の変化を監視 =====
ペアリングの結果を受信すため、<code>QBluetoothLocalDevice::pairingFinished</code>シグナルに接続する。<br>
これにより、ペアリング成功 / 失敗の通知を受け取ることができる。<br>
<br>
<syntaxhighlight lang="c++">
connect(&localDevice, &QBluetoothLocalDevice::pairingFinished, [](const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) {
    if (pairing == QBluetoothLocalDevice::Paired) {
      qDebug() << "ペアリング成功:" << address.toString();
    }
    else {
      qDebug() << "ペアリング失敗:" << address.toString();
    }
});
</syntaxhighlight>
<br>
===== PINコード確認のシグナル (必要な場合のみ) =====
PINコードが必要なデバイスは、<code>BluetoothLocalDevice::pairingDisplayConfirmation</code>シグナルに接続する。<br>
これにより、PINコードの確認が必要な場合に通知を受け取ることができる。<br>
<br>
<syntaxhighlight lang="c++">
connect(&localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, [](const QBluetoothAddress &address, QString pin) {
    qDebug() << "PINコード確認: " << address.toString() << pin;
});
</syntaxhighlight>
<br>
===== ペアリング要求 =====
ペアリングを開始するため、ペアリングするデバイスのBluetoothアドレスを指定して、<code>QBluetoothLocalDevice::requestPairing</code>メソッドを実行する。<br>
<br>
ペアリングの結果は、<code>QBluetoothLocalDevice::pairingFinished</code>シグナルで受信して、成功 / 失敗に応じた処理を行う。<br>
<br>
<syntaxhighlight lang="c++">
QBluetoothAddress targetAddress("XX:XX:XX:XX:XX:XX"); // 接続先アドレス
localDevice.requestPairing(targetAddress, QBluetoothLocalDevice::Paired);
</syntaxhighlight>
<br>
===== 組み合わせ =====
<syntaxhighlight lang="c++">
// BLEデバイスとのペアリング操作を管理するクラス
// ペアリングの開始と解除, ペアリング状態の監視, PINコード認証
  #include <QObject>
  #include <QObject>
  #include <QBluetoothLocalDevice>
  #include <QBluetoothLocalDevice>
  #include <QBluetoothAddress>
  #include <QBluetoothAddress>
#include <memory>
  #include <QDebug>
  #include <QDebug>
   
   
804行目: 908行目:
   
   
  private:
  private:
     std::unique_ptr<QBluetoothLocalDevice> localDevice;
     QBluetoothLocalDevice localDevice; // ローカルのBLEデバイスを管理するオブジェクト
   
   
    // ペアリング状態を表す文字列
     QString getPairingStatusString(QBluetoothLocalDevice::Pairing status)
     QString getPairingStatusString(QBluetoothLocalDevice::Pairing status)
     {
     {
814行目: 919行目:
           default:                                      return "不明な状態";
           default:                                      return "不明な状態";
       }
       }
    }
    // BLEデバイスが使用可能な状態かどうかを確認
    bool isDeviceReady() const
    {
      if (!localDevice || !localDevice->isValid()) return false;
      return localDevice.hostMode() != QBluetoothLocalDevice::HostPoweredOff;
    }
    // BLEデバイスのホストモードを設定
    void setHostMode(QBluetoothLocalDevice::HostMode mode)
    {
      if (isDeviceReady()) localDevice.setHostMode(mode);
    }
    // ホスト側においてBLEが利用可能かどうかを確認
    bool isBluetoothAvailable() const
    {
      return QBluetoothLocalDevice::allDevices().count() > 0;
     }
     }
   
   
  public:
  public:
     explicit BLEPairing(QObject* parent = nullptr) : QObject(parent)
     explicit BLEPairing(QObject *parent = nullptr) : QObject(parent)
     {
     {
       try {
       try {
          // ローカルデバイスの初期化
          localDevice = std::make_unique<QBluetoothLocalDevice>(this);
           // シグナルの接続
           // シグナルの接続
           connect(localDevice.get(), &QBluetoothLocalDevice::pairingFinished, this, &BLEPairing::onPairingFinished);
           connect(&localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BLEPairing::onPairingFinished);
           connect(localDevice.get(), &QBluetoothLocalDevice::error, this, &BLEPairing::onError);
           connect(&localDevice, &QBluetoothLocalDevice::error, this, &BLEPairing::onError);
           connect(localDevice.get(), &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BLEPairing::onPairingDisplayConfirmation);
           connect(&localDevice, &QBluetoothLocalDevice::pairingDisplayConfirmation, this, &BLEPairing::onPairingDisplayConfirmation);
           connect(localDevice.get(), &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BLEPairing::onPairingDisplayPinCode);
           connect(&localDevice, &QBluetoothLocalDevice::pairingDisplayPinCode, this, &BLEPairing::onPairingDisplayPinCode);
       }
       }
       catch (const std::exception &e) {
       catch (const std::exception &e) {
835行目: 956行目:
     }
     }
   
   
     // ペアリングを開始
     ~BLEPairing()
    {
      if (localDevice) {
          disconnect(&localDevice);  // 全ての接続を解除
      }
    }
    // 指定したデバイスとのペアリングを開始
    // 30秒のタイムアウトを設定 (失敗時はエラーを通知)
     void requestPairing(const QBluetoothAddress &address)
     void requestPairing(const QBluetoothAddress &address)
     {
     {
       try {
       try {
           if (!localDevice->isValid()) {
           if (!isDeviceReady()) {
             emit errorOccurred("ローカルBluetoothデバイスが無効です");
             emit errorOccurred("ローカルBluetoothデバイスが無効です");
             return;
             return;
           }
           }
          // タイムアウトの設定
          QTimer::singleShot(30000, this, [this, address]() {
            if (getPairingStatus(address) != QBluetoothLocalDevice::Paired) {
                emit errorOccurred("ペアリングがタイムアウトしました");
            }
          });
   
   
           qDebug() << "ペアリングを開始: " << address.toString();
           qDebug() << "ペアリングを開始: " << address.toString();
           localDevice->requestPairing(address, QBluetoothLocalDevice::Paired);
           localDevice.requestPairing(address, QBluetoothLocalDevice::Paired);
       }
       }
       catch (const std::exception &e) {
       catch (const std::exception &e) {
           QString errorMsg = QString("ペアリング開始エラー: %1").arg(e.what());
           emit errorOccurred("ペアリング開始時に予期せぬエラーが発生しました");
          qDebug() << errorMsg;
          emit errorOccurred(errorMsg);
       }
       }
     }
     }
   
   
     // ペアリングを解除
     // 指定したBLEデバイスとのペアリングを解除
     void removePairing(const QBluetoothAddress& address)
     void removePairing(const QBluetoothAddress& address)
     {
     {
       try {
       try {
           if (!localDevice->isValid()) {
           if (!localDevice.isValid()) {
             emit errorOccurred("ローカルBluetoothデバイスが無効");
             emit errorOccurred("ローカルBluetoothデバイスが無効");
             return;
             return;
864行目: 998行目:
   
   
           qDebug() << "ペアリングを解除: " << address.toString();
           qDebug() << "ペアリングを解除: " << address.toString();
           localDevice->requestPairing(address, QBluetoothLocalDevice::Unpaired);
           localDevice.requestPairing(address, QBluetoothLocalDevice::Unpaired);
       }
       }
       catch (const std::exception &e) {
       catch (const std::exception &e) {
873行目: 1,007行目:
     }
     }
   
   
     // ペアリング状態を確認
     // 指定したBLEデバイスとのペアリング状態を確認
     QBluetoothLocalDevice::Pairing getPairingStatus(const QBluetoothAddress &address)
     QBluetoothLocalDevice::Pairing getPairingStatus(const QBluetoothAddress &address)
     {
     {
       try {
       try {
           if (!localDevice->isValid()) {
           if (!localDevice.isValid()) {
             emit errorOccurred("ローカルBluetoothデバイスが無効");
             emit errorOccurred("ローカルBluetoothデバイスが無効");
             return QBluetoothLocalDevice::Unpaired;
             return QBluetoothLocalDevice::Unpaired;
           }
           }
   
   
           return localDevice->pairingStatus(address);
           return localDevice.pairingStatus(address);
       }
       }
       catch (const std::exception &e) {
       catch (const std::exception &e) {
893行目: 1,027行目:
   
   
  signals:
  signals:
     void pairingComplete(const QBluetoothAddress& address, bool success);
     void pairingComplete(const QBluetoothAddress& address, bool success);             // ペアリング完了通知
     void pairingConfirmationRequired(const QBluetoothAddress& address, QString pin);
     void pairingConfirmationRequired(const QBluetoothAddress& address, QString pin); // PIN確認要求通知
     void errorOccurred(const QString& error);
     void errorOccurred(const QString& error); // エラー通知
   
   
  private slots:
  private slots:
    // ペアリング完了時
     void onPairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
     void onPairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing)
     {
     {
905行目: 1,040行目:
     }
     }
   
   
    // BLEエラー発生時
     void onError()
     void onError()
     {
     {
       QString errorMsg = "Bluetoothデバイスでエラーが発生";
      QBluetoothLocalDevice::Error error = localDevice->error();
       qDebug() << errorMsg;
       QString errorMsg;
      switch (error) {
          case QBluetoothLocalDevice::NoError:
            errorMsg = "エラーなし";
            break;
          case QBluetoothLocalDevice::PairingError:
            errorMsg = "ペアリングエラー";
            break;
          case QBluetoothLocalDevice::UnknownError:
          default:
            errorMsg = "不明なエラー";
            break;
      }
       qDebug() << "Bluetoothエラー: " << errorMsg;
       emit errorOccurred(errorMsg);
       emit errorOccurred(errorMsg);
     }
     }
   
   
    // ペアリング時のPIN確認要求処理
     void onPairingDisplayConfirmation(const QBluetoothAddress &address, QString pin)
     void onPairingDisplayConfirmation(const QBluetoothAddress &address, QString pin)
     {
     {
920行目: 1,072行目:
     }
     }
   
   
    // PINコード表示要求時
     void onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin)
     void onPairingDisplayPinCode(const QBluetoothAddress &address, QString pin)
     {
     {
954行目: 1,107行目:
  #include <QLowEnergyCharacteristic>
  #include <QLowEnergyCharacteristic>
  #include <QTimer>
  #include <QTimer>
#include <memory>
  #include <QDebug>
  #include <QDebug>
   
   
962行目: 1,114行目:
   
   
  private:
  private:
     std::unique_ptr<QLowEnergyController> controller;
     QLowEnergyController controller;
     std::unique_ptr<QTimer> reconnectTimer;
     QTimer               reconnectTimer;
     QBluetoothDeviceInfo currentDevice;
     QBluetoothDeviceInfo currentDevice;
     bool autoReconnect = false;
     bool autoReconnect = false;
969行目: 1,121行目:
     void connectControllerSignals()
     void connectControllerSignals()
     {
     {
       connect(controller.get(), &QLowEnergyController::connected, this, &BLEConnection::onConnected);
       connect(&controller, &QLowEnergyController::connected, this, &BLEConnection::onConnected);
       connect(controller.get(), &QLowEnergyController::disconnected, this, &BLEConnection::onDisconnected);
       connect(&controller, &QLowEnergyController::disconnected, this, &BLEConnection::onDisconnected);
       connect(controller.get(), &QLowEnergyController::serviceDiscovered, this, &BLEConnection::onServiceDiscovered);
       connect(&controller, &QLowEnergyController::serviceDiscovered, this, &BLEConnection::onServiceDiscovered);
       connect(controller.get(), static_cast<void(QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error), this, &BLEConnection::onError);
       connect(&controller, static_cast<void(QLowEnergyController::*)(QLowEnergyController::Error)>(&QLowEnergyController::error), this, &BLEConnection::onError);
       connect(controller.get(), &QLowEnergyController::stateChanged, this, &BLEConnection::onStateChanged);
       connect(&controller, &QLowEnergyController::stateChanged, this, &BLEConnection::onStateChanged);
     }
     }
   
   
1,084行目: 1,236行目:
     {
     {
       // 再接続タイマの初期化
       // 再接続タイマの初期化
       reconnectTimer = std::make_unique<QTimer>(this);
       reconnectTimer.setInterval(5000);  // 5秒間隔で再接続
      reconnectTimer->setInterval(5000);  // 5秒間隔で再接続
       reconnectTimer.setSingleShot(true);
       reconnectTimer->setSingleShot(true);


       connect(reconnectTimer.get(), &QTimer::timeout, this, &BLEConnection::onReconnectTimeout);
       connect(&reconnectTimer &QTimer::timeout, this, &BLEConnection::onReconnectTimeout);
     }
     }
   
   
1,098行目: 1,249行目:


           // コントローラの初期化
           // コントローラの初期化
          controller = std::make_unique<QLowEnergyController>(device, this);
           connectControllerSignals();
           connectControllerSignals();


           // 接続パラメータの設定
           // 接続パラメータの設定
           controller->setRemoteAddressType(QLowEnergyController::PublicAddress);
           controller.setRemoteAddressType(QLowEnergyController::PublicAddress);


           // 接続開始
           // 接続開始
           controller->connectToDevice();
           controller.connectToDevice();
           currentDevice = device;
           currentDevice = device;
       }
       }
1,120行目: 1,270行目:
       try {
       try {
           if (controller) {
           if (controller) {
             controller->disconnectFromDevice();
             controller.disconnectFromDevice();
             reconnectTimer->stop();
             reconnectTimer.stop();
           }
           }
       }
       }
1,136行目: 1,286行目:
       autoReconnect = enable;
       autoReconnect = enable;
       if (!enable) {
       if (!enable) {
           reconnectTimer->stop();
           reconnectTimer.stop();
       }
       }
     }
     }
1,151行目: 1,301行目:
     {
     {
       qDebug() << "デバイスに接続";
       qDebug() << "デバイスに接続";
       reconnectTimer->stop();
       reconnectTimer.stop();
       emit connected();
       emit connected();
   
   
       // サービスの探索を開始
       // サービスの探索を開始
       controller->discoverServices();
       controller.discoverServices();
     }
     }
   
   
1,166行目: 1,316行目:
       if (autoReconnect) {
       if (autoReconnect) {
           qDebug() << "再接続を試行...";
           qDebug() << "再接続を試行...";
           reconnectTimer->start();
           reconnectTimer.start();
       }
       }
     }
     }
1,174行目: 1,324行目:
       qDebug() << "サービスを発見: " << uuid.toString();
       qDebug() << "サービスを発見: " << uuid.toString();
   
   
       QLowEnergyService* service = controller->createServiceObject(uuid, this);
       QLowEnergyService* service = controller.createServiceObject(uuid, this);
       if (service) {
       if (service) {
           connectServiceSignals(service);
           connectServiceSignals(service);
1,187行目: 1,337行目:
       emit errorOccurred(errorMessage);
       emit errorOccurred(errorMessage);
   
   
       if (autoReconnect && error != QLowEnergyController::InvalidBluetoothAdapterError) reconnectTimer->start();
       if (autoReconnect && error != QLowEnergyController::InvalidBluetoothAdapterError) reconnectTimer.start();
     }
     }


1,200行目: 1,350行目:
       if (autoReconnect && currentDevice.isValid()) {
       if (autoReconnect && currentDevice.isValid()) {
           qDebug() << "再接続を試行...";
           qDebug() << "再接続を試行...";
           controller->connectToDevice();
           controller.connectToDevice();
       }
       }
     }
     }