Beispiel #1
0
MainWindow::MainWindow(QMQTT::Client *client, QWidget *parent) :
    QMainWindow(parent),
    _client(client),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->conForm->init(client);
    ui->pubForm->init(client);
    ui->subForm->init(client);

    //add pushBtuoon slots
    connect(ui->pushButtonConnect,SIGNAL(clicked(bool)),this,SLOT(connectServer()));
    connect(ui->pushButtonPusblish,SIGNAL(clicked(bool)),this,SLOT(publishTopic()));
    connect(ui->pushButtonSubscribe,SIGNAL(clicked(bool)),this,SLOT(subscribeTopic()));
    connect(ui->pushButtonQuit,SIGNAL(clicked(bool)),this,SLOT(quitApp()));
    connect(ui->pushButtonClear,SIGNAL(clicked(bool)),this,SLOT(clearMsg()));
    connect(ui->pushButtonAbout,SIGNAL(clicked(bool)),this,SLOT(aboutApp()));

    //connform slots
    connect(_client, SIGNAL(disconnected()), ui->conForm, SLOT(updateUiStatus()));
    connect(_client, SIGNAL(connected()), ui->conForm, SLOT(updateUiStatus()));
    //mainwindow slots
    connect(_client, SIGNAL(connected()), this, SLOT(onMQTT_Connected()));
    connect(_client, SIGNAL(connacked(quint8)), this, SLOT(onMQTT_Connacked(quint8)));
    connect(_client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onMQTT_error(QAbstractSocket::SocketError)));
    connect(_client, SIGNAL(published(QMQTT::Message &)), this, SLOT(onMQTT_Published(QMQTT::Message &)));
    connect(_client, SIGNAL(pubacked(quint8, quint16)), this, SLOT(onMQTT_Pubacked(quint8, quint16)));
    connect(_client, SIGNAL(received(const QMQTT::Message &)), this, SLOT(onMQTT_Received(const QMQTT::Message &)));
    connect(_client, SIGNAL(subscribed(const QString &)), this, SLOT(onMQTT_subscribed(const QString &)));
    connect(_client, SIGNAL(subacked(quint16, quint8)), this, SLOT(onMQTT_subacked(quint16, quint8)));
    connect(_client, SIGNAL(unsubscribed(const QString &)), this, SLOT(onMQTT_unsubscribed(const QString &)));
    connect(_client, SIGNAL(unsubacked(quint16)), this, SLOT(onMQTT_unsubacked(quint16)));
    connect(_client, SIGNAL(pong()), this, SLOT(onMQTT_Pong()));
    connect(_client, SIGNAL(disconnected()), this, SLOT(onMQTT_disconnected()));
}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    client = new QMQTT::Client();
    d = new Dialog();
    state_dev1 = 0;
    ui->statusd1->setText("OFF");


    //mainwindow slots
    connect(client, SIGNAL(connected()), this, SLOT(onMQTT_Connected()));

    //todo: should emit on server suback
    connect(client, SIGNAL(error(QMQTT::ClientError)), this, SLOT(onMQTT_error(QMQTT::ClientError)));

    //slots changes
    //API:  void published(const QMQTT::Message& message);
    connect(client,SIGNAL(published(const QMQTT::Message &)),this,SLOT(onMQTT_Published(const QMQTT::Message &)));

    //todo: should emit on server suback
    connect(client, SIGNAL(received(const QMQTT::Message &)), this, SLOT(onMQTT_Received(const QMQTT::Message &)));
    connect(client, SIGNAL(subscribed(const QString &)), this, SLOT(onMQTT_subscribed(const QString &)));

    //todo: should emit on server suback
    connect(client, SIGNAL(unsubscribed(const QString &)), this, SLOT(onMQTT_unsubscribed(const QString &)));
    //todo: should emit on server suback
    connect(client, SIGNAL(disconnected()), this, SLOT(onMQTT_disconnected()));

    //connect(d, SIGNAL(accepted()), this, SLOT(onReadSetting()));
    connect(d, SIGNAL(updateDat()), this, SLOT(onReadSetting()));

    this->onReadSetting();
    client->setHost(QHostAddress::LocalHost);
    client->setPort(1883);
    client->setClientId("qt1");
    client->connectToHost();


}