<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema con API bluetooth]]></title><description><![CDATA[<p dir="auto">Buenas, he estado intentando utilizar la API de bluetooth que tiene implementado Qt con el fin de desarrollar una aplicación para la búsqueda de dispositivos cercanos.<br />
Una vez conseguí que me devolviese los valores de los dispositivos cercanos, me percaté de que si alguno de ellos se apagaba me lo iba a seguir mostrando y si encendía o acercaba uno nuevo éste no sería detectado. Únicamente me va a mostrar los dispositivos que previamente han sido descubiertos por la propia herramienta de Ubuntu (estoy trabajando en Linux) para la búsqueda de dispositivos bluetooth. Aquí os dejo el código:</p>
<p dir="auto">Main.cpp<br />
#include "mainwindow.h"<br />
#include &lt;QApplication&gt;<br />
#include &lt;QBluetoothLocalDevice&gt;<br />
#include &lt;QDebug&gt;<br />
#include &lt;QBluetoothDeviceDiscoveryAgent&gt;<br />
#include &lt;QtBluetooth/QBluetoothLocalDevice&gt;<br />
//! [include]<br />
#include &lt;QtCore/QCoreApplication&gt;<br />
#include &lt;QtCore/QDebug&gt;<br />
#include &lt;QtCore/QFile&gt;<br />
#include &lt;QtCore/QObject&gt;<br />
#include &lt;QtBluetooth/QBluetoothDeviceDiscoveryAgent&gt;<br />
#include &lt;QtBluetooth/QBluetoothServiceDiscoveryAgent&gt;<br />
#include &lt;QtBluetooth/QBluetoothTransferManager&gt;<br />
#include &lt;QtBluetooth/QBluetoothTransferRequest&gt;<br />
#include &lt;QtBluetooth/QBluetoothTransferReply&gt;</p>
<p dir="auto">#include &lt;QtBluetooth/QLowEnergyController&gt;<br />
#include &lt;QtBluetooth/QLowEnergyService&gt;<br />
#include &lt;QtBluetooth/QLowEnergyCharacteristic&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{</p>
<pre><code>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&lt;QBluetoothAddress&gt; remotes;
    remotes = localDevice.connectedDevices();
    qDebug() &lt;&lt; remotes;
}
MyClass hola;
hola.startDeviceDiscovery();

//while( 1);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void MyClass::startDeviceDiscovery()<br />
{</p>
<pre><code>// Create a discovery agent and connect to its signals
QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
        this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));

// Start a discovery
discoveryAgent-&gt;start();

//...
</code></pre>
<p dir="auto">}</p>
<p dir="auto">// In your local slot, read information about the found devices<br />
void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &amp;device)<br />
{<br />
qDebug() &lt;&lt; "Found new device:" &lt;&lt; <a href="http://device.name" target="_blank" rel="noopener noreferrer nofollow ugc">device.name</a>() &lt;&lt; '(' &lt;&lt; device.address().toString()&lt;&lt;'  ' &lt;&lt; device.minorDeviceClass()&lt;&lt; ')';<br />
}</p>
<p dir="auto">Un saludo.</p>
]]></description><link>https://forum.qt.io/topic/89806/problema-con-api-bluetooth</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 12:50:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/89806.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 13 Apr 2018 10:24:07 GMT</pubDate><ttl>60</ttl></channel></rss>