标题:之前写了个18B20的驱动,现在写了个界面想把数据显示出来,发现有几个问题
作者:caffee_1989
日期:2011-04-12 20:01
内容:
我把代码贴出来,希望有人能帮忙看看,主要有3个问题:
1、lcdnumber中能够实时显示数据,但label中只能显示最后一次采集的温度。
2、lcdnumber和label只显示整数,小数点后的都没显示,我好象把显示数据定义为double型了。
3、程序中我一共采集20次数据,再采集过程中点击quit和stop都不能响应,该怎么改善。
DS18B20.h(头文件)
#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include
class QLabel;
class QString;
class QPushButton;
class QLCDNumber;
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0, const char *name = 0);
int fd;
private slots:
void start();
void stop();
private:
QLabel *label;
QString string;
QPushButton *startbutton;
QPushButton *stopbutton;
QPushButton *quitbutton;
QLCDNumber *lcdnumber;
};
#endif
DS18B20.cpp
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "DS18B20.h"
Widget::Widget(QWidget *parent, const char *name): QWidget(parent, name)
{
setCaption(tr("DS18B20"));
startbutton = new QPushButton(tr("start"),this);
stopbutton = new QPushButton(tr("stop"),this);
quitbutton = new QPushButton(tr("quit"),this);
lcdnumber = new QLCDNumber(this);
label = new ..
#1 [caffee_1989 04-12 20:02]
本人刚学qt,希望能帮忙看看,可能对于大家只是很简单的事。
#2 [frog 04-12 20:49]
不能在start()函数中,写这段代码。
for(int i=0;i
#3 [frog 04-12 20:53]
建议你使用void timerEvent( QTimerEvent * event ),使用int timerId;timerId = timerStart(1000);启用定时器,定时的时间间隔为1秒。
#4 [frog 04-12 21:29]
res = double(tmp/10);应该改为(double)tmp / 10;
#5 回 4楼(frog) 的帖子 [caffee_1989 04-12 22:23]
非常感谢啊,听了您的意见终于改好了,再次谢谢。不过按您说的改了之后,第一个问题也解决了,请问知道是什么原因不?