Diferència entre revisions de la pàgina «Guia per a desenvolupar l'ex07 dels exercicis de QML»
Salta a la navegació
Salta a la cerca
m |
|||
Línia 86: | Línia 86: | ||
} | } | ||
} | } | ||
+ | |||
+ | = ex07a_03 = | ||
+ | == rerefonsmqtt.h == | ||
+ | #ifndef REREFONSMQTT_H | ||
+ | #define REREFONSMQTT_H | ||
+ | |||
+ | #include <QObject> | ||
+ | #include <QMqttClient> | ||
+ | |||
+ | class RerefonsMqtt : public QObject | ||
+ | { | ||
+ | Q_OBJECT | ||
+ | public: | ||
+ | explicit RerefonsMqtt(QObject *parent = nullptr); | ||
+ | |||
+ | signals: | ||
+ | void senyalEstatConnexioMqtt(int nEstatConnexioMqtt); | ||
+ | |||
+ | public slots: | ||
+ | void vBotoConnectaDesconnectaMqtt(); | ||
+ | |||
+ | private: | ||
+ | int m_nEstat; | ||
+ | }; | ||
+ | |||
+ | #endif // REREFONSMQTT_H |
Revisió del 12:17, 8 feb 2021
Contingut
ex07a_01
main.qml
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 640 height: 480 visible: true title: qsTr("ex07a - v0.1") EstatMqtt{ anchors.centerIn: parent } }
EstatMqtt.qml
import QtQuick 2.4 EstatMqttForm { }
EstatMqttForm.ui.qml
import QtQuick 2.4 import QtQuick.Controls 2.15 Item { id: item1 width: 400 height: 400 property alias btConnecta: btConnecta property alias textInfo: textInfo Text { id: textInfo y: 56 height: 53 color: "#ee2222" text: qsTr("MQTT desconnectat") anchors.left: parent.left anchors.right: parent.right anchors.bottom: btConnecta.top font.pixelSize: 35 horizontalAlignment: Text.AlignHCenter anchors.bottomMargin: 25 anchors.rightMargin: 10 anchors.leftMargin: 10 font.bold: true } Button { id: btConnecta x: 164 y: 214 text: qsTr("&Connecta") anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter } }
ex07a_02
EstatMqttForm.ui.qml
property alias btLedBlanc: btLedBlanc Button { id: btLedBlanc x: 169 text: qsTr("Encén led blanc") anchors.top: btConnecta.bottom anchors.horizontalCenterOffset: 0 anchors.topMargin: 25 anchors.horizontalCenter: btConnecta.horizontalCenter enabled: false }
main.qml
title: qsTr("ex07a - v0.2") EstatMqtt{ anchors.centerIn: parent btConnecta.onClicked: { textInfo.text = (textInfo.text === qsTr("MQTT desconnectat"))?qsTr("MQTT connectat"):qsTr("MQTT desconnectat") textInfo.color = (textInfo.text === qsTr("MQTT desconnectat"))?"#ee2222":"#22ee22" btConnecta.text = (textInfo.text === qsTr("MQTT desconnectat"))?qsTr("&Connecta"):qsTr("Des&connecta") btLedBlanc.enabled = (textInfo.text === qsTr("MQTT desconnectat"))?false:true } btLedBlanc.onClicked: { btLedBlanc.text = (btLedBlanc.text === qsTr("Encén led blanc"))?qsTr("Apaga led blanc"):qsTr("Encén led blanc") } }
ex07a_03
rerefonsmqtt.h
#ifndef REREFONSMQTT_H #define REREFONSMQTT_H #include <QObject> #include <QMqttClient> class RerefonsMqtt : public QObject { Q_OBJECT public: explicit RerefonsMqtt(QObject *parent = nullptr); signals: void senyalEstatConnexioMqtt(int nEstatConnexioMqtt); public slots: void vBotoConnectaDesconnectaMqtt(); private: int m_nEstat; }; #endif // REREFONSMQTT_H