创建http服务器:
HttpServer::instance().run(QHostAddress::Any, 8081);
创建mqtt服务器(需要输入mqtt服务器和mqtt端口mqtt = new QMQTT::Client(QHostAddress("192.168.22.140"), 1883); //MQTT固定服务器和端口):
connect(link_host_bt, SIGNAL(clicked()), this, SLOT(on_connect_clicked()));
connect(sub_bt, SIGNAL(clicked()), this, SLOT(on_sub_clicked()));
connect(rel_bt, SIGNAL(clicked()), this, SLOT(on_pub_clicked()));
void pc_probject::on_connect_clicked()
{
qDebug() << "link_host_clicked";
//mqtt = new QMQTT::Client(QHostAddress("192.168.22.140"), 1883); //MQTT固定服务器和端口
mqtt = new QMQTT::Client(QHostAddress(QString(host_name->text())),host_pro->text().toInt());
connect(mqtt, SIGNAL(connected()), this, SLOT(mqtt_connect_success()));
connect(mqtt, SIGNAL(disconnected()), this, SLOT(mqtt_disconnect()));
connect(mqtt, SIGNAL(subscribed(QString, quint8)), this, SLOT(mqtt_sub_success(QString, quint8)));
connect(mqtt, SIGNAL(received(QMQTT::Message)), this, SLOT(mqtt_recv_msg(QMQTT::Message)));
mqtt->setCleanSession(true);
mqtt->connectToHost(); //连接mqtt
udp_send->resive(udp_reciver, mqtt);
}
下载地址:(5条消息) 64位Windows,QTmqtt客户端和http服务端库文件-智能家居文档类资源-CSDN文库