演示链接
【QT上位机/嵌入式项目】基于IMX6ull--Bluez蓝牙健康助手上位机
代码实现
代码非完整代码,有需要源码可私信我!
#include "bluetooth_page.h"
#include "remoteselector.h"
#include "chatserver.h"
#include "chatclient.h"
#include <qbluetoothuuid.h>
#include <qbluetoothserver.h>
#include <qbluetoothservicediscoveryagent.h>
#include <qbluetoothdeviceinfo.h>
#include <qbluetoothlocaldevice.h>
#include <QGuiApplication>
#include <QScreen>
#include <QRect>
#include <QTimer>
#include <QDebug>
#include <QTabBar>
#include <QHeaderView>
#include <QTableView>
ChatServer *server;
static const QLatin1String
serviceUuid("e8e10f95-1a70-4b27-9ccf-02010264e9c8");
Bluetooth_Page::Bluetooth_Page(QWidget *parent, Home_Page *homePageInstance, PageManage *pageManager)
: QWidget(parent), pageManager(pageManager), homePage(homePageInstance)
{
blue_page_Widget = new QWidget(this);
blue_page_Widget->setGeometry(0, 0, 800, 480);
blue_page_Widget->setFixedSize(800, 480);
layoutInit();
localAdapterInit();
}
Bluetooth_Page::~Bluetooth_Page()
{
qDeleteAll(clients);
delete server;
}
/* 初始化本地蓝牙,作为服务端 */
void Bluetooth_Page::localAdapterInit()
{
/* 查找本地蓝牙的个数 */
localAdapters = QBluetoothLocalDevice::allDevices();
qDebug() << "localAdapter: " << localAdapters.count();
QBluetoothLocalDevice localDevice;
localDevice.setHostMode(QBluetoothLocalDevice::HostDiscoverable);
QBluetoothAddress adapter = QBluetoothAddress();
remoteSelector = new RemoteSelector(adapter, this);
connect(remoteSelector,
SIGNAL(newServiceFound(QListWidgetItem*)),
this, SLOT(newServiceFound(QListWidgetItem*)));
/* 初始化服务端 */
server = new ChatServer(homePage, this);
//server = new ChatServer(this);
connect(server, SIGNAL(clientConnected(