<file_sep>#ifndef MYTHERMOMETER_H
#define MYTHERMOMETER_H

#include <QWidget>

class MyThermometer : public QWidget
{
    Q_OBJECT
private:
    double temperature;
public:
    MyThermometer(QWidget *parent = 0);
    void paintEvent(QPaintEvent *);
    void setTemperature(double temperature);
};

#endif
<file_sep>#include "mythermometer.h"
#include <QPen>
#include <QPainter>

MyThermometer::MyThermometer(QWidget *parent) :
    QWidget(parent)
{

}

void MyThermometer::paintEvent(QPaintEvent *)
{
        QPainter painter(this);             // 创建QPainter一个对象
        QPen pen;
        QBrush brush;   //画刷 填充几何图形的调色板，由颜色和填充风格组成

        brush.setStyle(Qt::SolidPattern);

        if (37.2 > temperature){
            pen.setColor(Qt::green);            // 设置画笔颜色
            brush.setColor(Qt::green);
        }
        if (37.2 <= temperature) {
            pen.setColor(Qt::red);
            brush.setColor(Qt::red);
        }
        painter.setPen(pen);                // 设置画笔
        painter.drawRect(QRect(0, 0, 200, 30   ));
        painter.setBrush(brush);
        painter.drawRect(QRect(0, 0, temperature*2, 30  ));
}

void MyThermometer::setTemperature(double temperature)
{
    this->temperature=temperature;
}

<file_sep>/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp com.qdbus.demo.xml -p mainwindowinterface
 *
 * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#include "mainwindowinterface.h"

/*
 * Implementation of interface class ComQdbusServerInterface
 */

ComQdbusServerInterface::ComQdbusServerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
{
}

ComQdbusServerInterface::~ComQdbusServerInterface()
{
}

<file_sep>/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp com.qdbus.demo.xml -i mainwindow.h -a mainwindowadaptor
 *
 * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
 *
 * This is an auto-generated file.
 * Do not edit! All changes made to it will be lost.
 */

#include "mainwindowadaptor.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

/*
 * Implementation of adaptor class ServerAdaptor
 */

ServerAdaptor::ServerAdaptor(QObject *parent)
    : QDBusAbstractAdaptor(parent)
{
    // constructor
    setAutoRelaySignals(true);
}

ServerAdaptor::~ServerAdaptor()
{
    // destructor
}

void ServerAdaptor::server_get(const QString &name, int age, const QString &id, const QString &tel, const QString &adress, double temperature)
{
    // handle method call com.qdbus.server.server_get
    QMetaObject::invokeMethod(parent(), "server_get", Q_ARG(QString, name), Q_ARG(int, age), Q_ARG(QString, id), Q_ARG(QString, tel), Q_ARG(QString, adress), Q_ARG(double, temperature));
}

<file_sep>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

class MainWindowPrivate
{
    Q_DECLARE_PUBLIC(MainWindow)

public:

    QGSettings* m_settings;
    Dialog* m_dialog;
    thermometer* m_thermometer;
    QRegExp id_exp;
    QRegExp tel_exp;
    MainWindow* q_ptr;
    ComQdbusServerInterface *m_demoInter;

    MainWindowPrivate(MainWindow* parent)
    {
        q_ptr=parent;
    }

};

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , d_ptr(new MainWindowPrivate(this))
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QDBusConnection::sessionBus().connect("com.qdbus.server", "/com/qdbus/server", "com.qdbus.server", "send_to_client_ok", this, SLOT(client_get_ok(void)));
    QDBusConnection::sessionBus().connect("com.qdbus.server", "/com/qdbus/server", "com.qdbus.server", "send_to_client_error", this, SLOT(client_get_error(void)));

    Q_D(MainWindow);
    //id_exp.setPattern("^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$");
    d->id_exp.setPattern("^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$");
    //tel_exp.setPattern("^1(3[0-9]|5[0-3,5-9]|7[1-3,5-8]|8[0-9])\\d{8}$");
    d->tel_exp.setPattern("^1(3[0-9]|5[0-3,5-9]|7[1-3,5-8]|8[0-9])\\d{8}$");

    d->m_demoInter = new ComQdbusServerInterface("com.qdbus.server","/com/qdbus/server",QDBusConnection::sessionBus(),this);

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    Q_D(MainWindow);
    //绑定QGSetting与xml
    //m_settings = new QGSettings("com.QGSettingDemo.test","/com/QGSettingDemo/test/");
    d->m_settings = new QGSettings("com.QGSettingDemo.test","/com/QGSettingDemo/test/");
    //获取QGSetting发出的KEY值改变信号,在界面同步更新
    //connect (m_settings,&QGSettings::changed,[=](const QString key)
    connect (d->m_settings, &QGSettings::changed, [=](const QString key)
    {
        if ("name" == key) {
            QString name = d->m_settings->get("name").toString();
            ui->lineEdit_name->setText(name);
        }

        if ("age" == key) {
            QString age = d->m_settings->get("age").toString();
            ui->lineEdit_age->setText(age);
        }

        if ("id" == key) {
            QString id = d->m_settings->get("id").toString();
            ui->lineEdit_id->setText(id);
        }

        if ("tel" == key) {
            QString tel = d->m_settings->get("tel").toString();
            ui->lineEdit_tel->setText(tel);
        }

        if ("adress" == key) {
            QString adress = d->m_settings->get("adress").toString();
            ui->lineEdit_adress->setText(adress);
        }

        if("temperature" == key) {
            QString temperature = d->m_settings->get("temperature").toString();
            ui->lineEdit_temperature->setText(temperature);
        }

    });

    do{
        if (false == ui->lineEdit_name->text().isEmpty()) {
            QString name = ui->lineEdit_name->text();

            if (d->m_settings) {
                d->m_settings->trySet("name",name);
            }

        } else {
            d->m_dialog = new Dialog(this);
            d->m_dialog->setLabel("请输入姓名");
            d->m_dialog->show();
            break;
        }

        if ( ui->lineEdit_age->text().toInt() > 0 ) {
            int age = ui->lineEdit_age->text().toInt();
            if (d->m_settings) {
                d->m_settings->trySet("age",age);
            }
        } else {
            d->m_dialog = new Dialog(this);
            d->m_dialog->setLabel("请输入正确年龄");
            d->m_dialog->show();
            break;
        }

        if (d->id_exp.exactMatch(ui->lineEdit_id->text())) {
            QString id = ui->lineEdit_id->text();
            if (d->m_settings) {
                d->m_settings->trySet("id",id);
            }
        } else {
            d->m_dialog = new Dialog(this);
            d->m_dialog->setLabel("请输入正确的身份证号");
            d->m_dialog->show();
            break;
        }

        if ( d->tel_exp.exactMatch(ui->lineEdit_tel->text())) {
            QString tel = ui->lineEdit_tel->text();
            if (d->m_settings) {
                d->m_settings->trySet("tel",tel);
            }
        } else {
            d->m_dialog = new Dialog(this);
            d->m_dialog->setLabel("请输入正确的手机号");
            d->m_dialog->show();
            break;
        }

        if (false == ui->lineEdit_tel->text().isEmpty()) {
            QString adress = ui->lineEdit_adress->text();
            if (d->m_settings) {
                d->m_settings->trySet("adress",adress);
            }
        } else {
            d->m_dialog = new Dialog(this);
            d->m_dialog->setLabel("请输入地址");
            d->m_dialog->show();
            break;
        }

        if (35.0 < ui->lineEdit_temperature->text().toDouble()) {
            double temperature = ui->lineEdit_temperature->text().toDouble();
            if (d->m_settings) {
                d->m_settings->trySet("temperature",temperature);
            }
        } else {
                d->m_dialog = new Dialog(this);
                d->m_dialog->setLabel("请输入正确的体温");
                d->m_dialog->show();
                break;
        }

//        Message 方式调用接口提供的函数
//        QDBusMessage message = QDBusMessage::createMethodCall(
//                                                             "com.qdbus.server",
//                                                             "/com/qdbus/server",
//                                                             "com.qdbus.server",
//                                                             "server_get");
//        message << ui->lineEdit_name->text()
//                << ui->lineEdit_age->text().toInt()
//                << ui->lineEdit_id->text()
//                << ui->lineEdit_tel->text()
//                << ui->lineEdit_adress->text()
//                << ui->lineEdit_temperature->text().toDouble();

//        QDBusConnection::sessionBus().call(message);

//      适配器方式调用接口提供的函数
        d->m_demoInter->server_get(ui->lineEdit_name->text(),
                                   ui->lineEdit_age->text().toInt(),
                                   ui->lineEdit_id->text(),
                                   ui->lineEdit_tel->text(),
                                   ui->lineEdit_adress->text(),
                                   ui->lineEdit_temperature->text().toDouble());

    } while(0);

}

void MainWindow::client_get_error()
{
    Q_D(MainWindow);
    d->m_thermometer= new thermometer(this);
    d->m_thermometer->setLabel("体温异常,禁止通行");
    d->m_thermometer->setProgressBar(ui->lineEdit_temperature->text().toDouble());
    d->m_thermometer->show();

}


void MainWindow::client_get_ok()
{
    Q_D(MainWindow);
    d->m_thermometer = new thermometer(this);
    d->m_thermometer->setLabel("体温正常,允许通行");
    d->m_thermometer->setProgressBar(ui->lineEdit_temperature->text().toDouble());
    d->m_thermometer->show();
}


<file_sep>#ifndef THERMOMETER_H
#define THERMOMETER_H

#include <QDialog>

namespace Ui {
class thermometer;
}

class thermometer : public QDialog
{
    Q_OBJECT

public:
    explicit thermometer(QWidget *parent = nullptr);
    ~thermometer();

    void setLabel(QString bugInfo);
    void setProgressBar(double temperature);

private:
    Ui::thermometer *ui;
};

#endif // THERMOMETER_H
<file_sep>Qt疫情软件分成Server和Client通过dbus数据总线通信
该Demo用以熟悉Qt插件机制，dbus 和 gsetting

Clinet部分利用正则表达式检测输入，通过Server注册的Dbus服务发送疫情数据给Server，Server判断是否通行

![image](https://user-images.githubusercontent.com/30315297/140595143-25433a9e-cc8e-4e8f-b867-8fa48af95cf4.png)
![image](https://user-images.githubusercontent.com/30315297/140595273-a1ea538d-fb8f-44e1-b020-9ead9d155791.png)

<file_sep>#ifndef ECHOINTERFACE_H
#define ECHOINTERFACE_H


#include <QString>
#include <QtPlugin>

//定义接口
class EchoInterface
{
public:
    virtual ~EchoInterface() = 0;
    virtual QString echo(const QString &message) = 0;
};

#define EchoInterface_iid "Examples.Plugin.EchoInterface"

QT_BEGIN_NAMESPACE
Q_DECLARE_INTERFACE(EchoInterface, EchoInterface_iid)
QT_END_NAMESPACE


#endif // ECHOINTERFACE_H
<file_sep>#include "mythermometer.h"
#include "mythermometerplugin.h"

#include <QtPlugin>

MyThermometerPlugin::MyThermometerPlugin(QObject *parent)
    : QObject(parent)
{
    m_initialized = false;
}

void MyThermometerPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
    if (m_initialized)
        return;

    // Add extension registrations, etc. here

    m_initialized = true;
}

bool MyThermometerPlugin::isInitialized() const
{
    return m_initialized;
}

QWidget *MyThermometerPlugin::createWidget(QWidget *parent)
{
    return new MyThermometer(parent);
}

QString MyThermometerPlugin::name() const
{
    return QLatin1String("MyThermometer");
}

QString MyThermometerPlugin::group() const
{
    return QLatin1String("MyThermometer");
}

QIcon MyThermometerPlugin::icon() const
{
    return QIcon();
}

QString MyThermometerPlugin::toolTip() const
{
    return QLatin1String("");
}

QString MyThermometerPlugin::whatsThis() const
{
    return QLatin1String("");
}

bool MyThermometerPlugin::isContainer() const
{
    return false;
}

QString MyThermometerPlugin::domXml() const
{
    return QLatin1String("<widget class=\"MyThermometer\" name=\"myThermometer\">\n</widget>\n");
}

QString MyThermometerPlugin::includeFile() const
{
    return QLatin1String("mythermometer.h");
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(mythermometerplugin, MyThermometerPlugin)
#endif // QT_VERSION < 0x050000
<file_sep>#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "dialog.h"
#include "thermometer.h"
#include "mainwindowinterface.h"
#include <QRegularExpression>
#include <QtDBus/QtDBus>
#include <QGSettings>
#include <QPainter>
#include <QMainWindow>
#include <QGlobalStatic>

namespace Ui {
class MainWindow;
}

class MainWindowPrivate;

class MainWindow : public QMainWindow
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(MainWindow)
public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:

    //录入输入框信息保存于GSettting xml
    void on_pushButton_clicked();

    //接受send_to_client是否通行信号
    void client_get_ok(void);
    void client_get_error(void);

private:

    MainWindowPrivate* d_ptr;
    Ui::MainWindow *ui;

    /*
    QGSettings* m_settings;
    Dialog* m_dialog;
    thermometer* m_thermometer;
    QRegExp id_exp;
    QRegExp tel_exp;
    */

};

#endif // MAINWINDOW_H
<file_sep>#ifndef INTERFACEPLUGIN_H
#define INTERFACEPLUGIN_H
#include <QtPlugin>

//定义接口
class InterfacePlugin
{
public:
    virtual ~InterfacePlugin() = 0 ;
    virtual void SetTemp(const double temp) = 0;
};

//唯一标识符
#define InterfacePlugin_iid "Test.Plugin.InterfacePlugin"
Q_DECLARE_INTERFACE(InterfacePlugin, InterfacePlugin_iid)


#endif // INTERFACEPLUGIN_H
<file_sep>/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp com.qdbus.demo.xml -i mainwindow.h -a mainwindowadaptor
 *
 * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#ifndef MAINWINDOWADAPTOR_H
#define MAINWINDOWADAPTOR_H

#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include "mainwindow.h"
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
QT_END_NAMESPACE

/*
 * Adaptor class for interface com.qdbus.server
 */
class ServerAdaptor: public QDBusAbstractAdaptor
{
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "com.qdbus.server")
    Q_CLASSINFO("D-Bus Introspection", ""
"  <interface name=\"com.qdbus.server\">\n"
"    <signal name=\"send_to_client_ok\"/>\n"
"    <signal name=\"send_to_client_error\"/>\n"
"    <method name=\"server_get\">\n"
"      <arg direction=\"in\" type=\"s\" name=\"name\"/>\n"
"      <arg direction=\"in\" type=\"i\" name=\"age\"/>\n"
"      <arg direction=\"in\" type=\"s\" name=\"id\"/>\n"
"      <arg direction=\"in\" type=\"s\" name=\"tel\"/>\n"
"      <arg direction=\"in\" type=\"s\" name=\"adress\"/>\n"
"      <arg direction=\"in\" type=\"d\" name=\"temperature\"/>\n"
"    </method>\n"
"  </interface>\n"
        "")
public:
    ServerAdaptor(QObject *parent);
    virtual ~ServerAdaptor();

public: // PROPERTIES
public Q_SLOTS: // METHODS
    void server_get(const QString &name, int age, const QString &id, const QString &tel, const QString &adress, double temperature);
Q_SIGNALS: // SIGNALS
    void send_to_client_error();
    void send_to_client_ok();
};

#endif
<file_sep>/*
 * This file was generated by qdbusxml2cpp version 0.8
 * Command line was: qdbusxml2cpp com.qdbus.demo.xml -p mainwindowinterface
 *
 * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
 *
 * This is an auto-generated file.
 * Do not edit! All changes made to it will be lost.
 */

#ifndef MAINWINDOWINTERFACE_H
#define MAINWINDOWINTERFACE_H

#include <QtCore/QObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtDBus/QtDBus>

/*
 * Proxy class for interface com.qdbus.server
 */
class ComQdbusServerInterface: public QDBusAbstractInterface
{
    Q_OBJECT
public:
    static inline const char *staticInterfaceName()
    { return "com.qdbus.server"; }

public:
    ComQdbusServerInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);

    ~ComQdbusServerInterface();

public Q_SLOTS: // METHODS
    inline QDBusPendingReply<> server_get(const QString &name, int age, const QString &id, const QString &tel, const QString &adress, double temperature)
    {
        QList<QVariant> argumentList;
        argumentList << QVariant::fromValue(name) << QVariant::fromValue(age) << QVariant::fromValue(id) << QVariant::fromValue(tel) << QVariant::fromValue(adress) << QVariant::fromValue(temperature);
        return asyncCallWithArgumentList(QStringLiteral("server_get"), argumentList);
    }

Q_SIGNALS: // SIGNALS
    void send_to_client_error();
    void send_to_client_ok();
};

namespace com {
  namespace qdbus {
    typedef ::ComQdbusServerInterface server;
  }
}
#endif
<file_sep>#ifndef ECHOPLUGIN_H
#define ECHOPLUGIN_H

#include "../Server/echointerface.h"

class EchoPlugin : public QObject, public EchoInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID EchoInterface_iid)
    Q_INTERFACES(EchoInterface)
public:
    explicit EchoPlugin(QObject *parent = 0);
    QString echo(const QString &message);
};

#endif // ECHOPLUGIN_H
<file_sep>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "echointerface.h"
#include <QDebug>

class MainWindowPrivate
{
    Q_DECLARE_PUBLIC(MainWindow)

public:
        int count;
        QStandardItemModel *model;
        MainWindow *q_ptr;
        bool LoadPlugin();
        EchoInterface *echoInterface;
        MainWindowPrivate(MainWindow* parent)
        {
            count = 0;
            model = new QStandardItemModel();
            q_ptr=parent;
        }
};

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , d_ptr(new MainWindowPrivate(this))
    , ui(new Ui::MainWindow)
{
    Q_D(MainWindow);

    ui->setupUi(this);
    //获得主窗口的大小
    int width = this->width();
    int height = this->height();
    //调整tableView窗口大小和主窗口一致
    ui->tableView->resize(width, height);
    ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

    //设置表格样式 
    d->model->setColumnCount(7);
    d->model->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit("姓名"));
    d->model->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit("年龄"));
    d->model->setHeaderData(2,Qt::Horizontal,QString::fromLocal8Bit("身份证号"));
    d->model->setHeaderData(3,Qt::Horizontal,QString::fromLocal8Bit("手机号"));
    d->model->setHeaderData(4,Qt::Horizontal,QString::fromLocal8Bit("住址"));
    d->model->setHeaderData(5,Qt::Horizontal,QString::fromLocal8Bit("体温"));
    d->model->setHeaderData(6,Qt::Horizontal,QString::fromLocal8Bit("是否放行"));

    ui->tableView->setModel(d->model);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::server_get(QString name , int age , QString id , QString tel , QString adress , double temperature)
{
    Q_D(MainWindow);

    d->model->setItem(d->count,0,new QStandardItem(name));
    d->model->setItem(d->count,1,new QStandardItem(QString::number(age)));
    d->model->setItem(d->count,2,new QStandardItem(id));
    d->model->setItem(d->count,3,new QStandardItem(tel));
    d->model->setItem(d->count,4,new QStandardItem(adress));
    d->model->setItem(d->count,5,new QStandardItem(QString::number(temperature)));

    if (37.2 <= temperature ) {
        d->model->setItem(d->count, 6, new QStandardItem(QString("否")));
        emit send_to_client_error();
    }

    if (temperature < 37.2) {
        d->model->setItem(d->count , 6, new QStandardItem(QString("是")));
        emit send_to_client_ok();
    }

    d->count++;

    if(d->LoadPlugin()){
        d->echoInterface->echo(QString::number(temperature));
    }

}


bool MainWindowPrivate::LoadPlugin()
{

    bool ret = true;
    //获取当前应用程序所在路径
    QDir pluginsDir(qApp->applicationDirPath());
    #if defined(Q_OS_WIN)
        if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() =="release"){
            pluginsDir.cdUp();
            pluginsDir.cdUp();
        }
    #elif defined(Q_OS_MAC)
        if (pluginsDir.dirName() == "MacOS")
        {
            pluginsDir.cdUp();
            pluginsDir.cdUp();
            pluginsDir.cdUp();
        }
    #elif defined(Q_OS_LINUX)
        pluginsDir.cdUp();
    #endif
        //切换到插件目录
        pluginsDir.cd("plugins");
        //遍历plugins目录下所有文件
        foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
            QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
            QObject *plugin = pluginLoader.instance();
            if (plugin) {
                //插件名称
                QString pluginName = plugin->metaObject()->className();
                //对插件初始化
                if (pluginName == "EchoPlugin") {
                    echoInterface = qobject_cast<EchoInterface*>(plugin);
                    if (echoInterface)
                        ret =  true;
                    break;
                }
                else {
                    ret = false;
                }
            }
        }
        return ret;
}
<file_sep>#include "echoplugin.h"
#include <QDebug>

EchoPlugin::EchoPlugin(QObject *parent) :
    QObject(parent)
{
}

QString EchoPlugin::echo(const QString &message)
{
    qDebug() << message;
    return message;
}
<file_sep>#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , m_dialog(new Ui::Dialog)
{
    m_dialog->setupUi(this);
}

Dialog::~Dialog()
{
    delete m_dialog;
}

void Dialog::setLabel(QString bugInfo)
{
    m_dialog->label->setText(bugInfo);
}


<file_sep>#include "mythermometer.h"
#include <QPen>
#include <QPainter>

MyThermometer::MyThermometer(QWidget *parent) :
    QWidget(parent)
{

}

void MyThermometer::paintEvent(QPaintEvent *)
{
        QPainter painter(this);             // 创建QPainter一个对象
        QPen pen;

        if (37.2 <= temperature){
            pen.setColor(Qt::green);            // 设置画笔颜色
        }
        if (37.2 > temperature) {
            pen.setColor(Qt::red);
        }
        painter.setPen(pen);                // 设置画笔
        painter.drawRect(QRect(1, 1, 300, 100));
        painter.restore();
}

void MyThermometer::setTemperature(double temperature)
{
    this->temperature=temperature;
}

<file_sep>#include "mainwindow.h"
#include <QApplication>
#include "mainwindowadaptor.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    //建立Dbus连接
    QDBusConnection connection = QDBusConnection::sessionBus();
    //注册Dbus服务
    connection.registerService("com.qdbus.server");
    //注册Dbus对象


    //用Object来导出信号和槽函数
    //connection.registerObject("/com/qdbus/server", &w, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals);

    //用适配器方式来导出信号和槽函数
    ServerAdaptor adaptor(&w);
    connection.registerObject("/com/qdbus/server", &w);


    return a.exec();
}
<file_sep>#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = nullptr);
    ~Dialog();

    //提供接口给主窗口修改错误信息接口
    void setLabel(QString bugInfo);

private:
    Ui::Dialog* m_dialog;
};

#endif // DIALOG_H
<file_sep>#include "thermometer.h"
#include "ui_thermometer.h"

thermometer::thermometer(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::thermometer)
{
    ui->setupUi(this);
}

thermometer::~thermometer()
{
    delete ui;
}

void thermometer::setLabel(QString bugInfo)
{
    ui->label->setText(bugInfo);
}

void thermometer::setProgressBar(double temperature)
{
    ui->myThermometer->setTemperature(temperature);
}
