自己用代码写成的界面,然后再加入一些代码,程序执行时没有错误,但是用Qt creator设计成的界面,再加入代码,虽然能编译成功,但是程序运行时出现段错误,各位大侠帮帮忙,下面是我的程序代码,用creator实现的
头文件
#ifndef GUOADC_H
#define GUOADC_H
#include <QtGui>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
//#include <sys/ioctl.h>
#include <sys/types.h>
#include <errno.h>
#include <fcntl.h>
//#include <linux/fs.h>
#include <string.h>
#include <QWidget>
namespace Ui {
class GuoAdc;
}
class GuoAdc : public QWidget
{
Q_OBJECT
public:
explicit GuoAdc(QWidget *parent = 0);
~GuoAdc();
private:
Ui::GuoAdc *ui;
public:
QSocketNotifier *notifier;
QLineEdit *disLineEdit;
private slots:
void readadc_value();
};
#endif // GUOADC_H
cpp文件
#include "guoadc.h"
#include "ui_guoadc.h"
static int adc_fd;
static char buffer[30];
static int len;
int value=-1;
GuoAdc::GuoAdc(QWidget *parent) :
QWidget(parent),
ui(new Ui::GuoAdc)
{
adc_fd=open("/dev/adc",0);
if(adc_fd<0)
{
perror("open adc device");
}
ui->setupUi(this);
notifier=new QSocketNotifier(adc_fd,QSocketNotifier::Read,this);
connect(notifier,SIGNAL(activated(int)),this,SLOT(readadc_value()));
}
GuoAdc::~GuoAdc()
{
delete ui;
}
void GuoAdc::readadc_value()
{
len=read(adc_fd,buffer,sizeof buffer-1);
if(len>0)
{
buffer[len]='\n';
sscanf(buffer,"%d",&value);
}
else
{
perror("read ADC Device");
}
QString tempStr;
disLineEdit->setText(tempStr.setNum(value));
}