#include "frmdata.h" #include "ui_frmdata.h" #include "quihelper.h" frmData::frmData(QWidget *parent) : QWidget(parent), ui(new Ui::frmData) { ui->setupUi(this); this->initForm(); } frmData::~frmData() { delete ui; } void frmData::initForm() { ui->widgetDataX->setProperty("border", "bold"); ui->widgetDataY->setProperty("border", "bold"); //定时器模拟数据 QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(setValue())); timer->start(1000); } void frmData::setValue() { double x1 = (rand() % 100); double x2 = (rand() % 1000); QString x = QString("%1.%2").arg(x1).arg(x2); setXValue(x.toDouble()); double y = (rand() % 100) + 1000; setYValue(y); } void frmData::setXValue(double value) { ui->labXValue->setText(QString::number(value)); } void frmData::setYValue(double value) { ui->labYValue->setText(QString::number(value)); }