• 3872阅读
  • 0回复

代码出现错误,各位大侠帮忙 [复制链接]

上一主题 下一主题
离线flyingucla
 
只看楼主 倒序阅读 楼主  发表于: 2012-04-16
文件
1 #ifndef TIMEREAD_H
2 #define TIMEREAD_H
3 #include <QtGui>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <sys/stat.h>
8 //#include <sys/ioctl.h>
9 #include <sys/types.h>
10 #include <errno.h>
11 #include <fcntl.h>
12 //#include <linux/fs.h>
13 #include <string.h>
14 #include <stdbool.h>
15 #include <QWidget>
16 namespace Ui {
17     class TimeRead;
18 }
19 class TimeRead : public QWidget
20 {
21 Q_OBJECT
22 public:
23   explicit TimeRead(QWidget *parent = 0);
24    ~TimeRead();
25 private:
26    Ui::TimeRead *ui;
27 public:
28    QSocketNotifier *notifier;
29 private slots:
30     void readtime();
31 };
32 #endif // TIMEREAD_H
源文件
1 #include "timeread.h" 2 #include "ui_timeread.h"
3 int fd;
4 unsigned long t[2];
5 //double time; 6 static int len;
7 static char buffer[30]; 8
9 TimeRead::TimeRead(QWidget *parent) :
10    QWidget(parent),
11    ui(new Ui::TimeRead)
12 {
13    fd = open("/dev/my_button", O_RDONLY);
14        if (fd < 0) {
15            perror("Open /dev/my_button failed.\n");
16        }
17    ui->setupUi(this);
18    notifier = new QSocketNotifier(fd,QSocketNotifier::Read,this);
19    connect(notifier,SIGNAL(activated(int)),this,SLOT(readtime()));
20 } 21
22 TimeRead::~TimeRead() 23 {
24    delete ui; 25 }
26 void TimeRead::readtime()
27 {
28 len=read(fd,buffer,sizeof buffer-1);
29    if(len>0)
30    {
31        time=(t[0]/100.0)+(t[1]/100.0/50625.0);
32        buffer[len]='\n';
33        sscanf(buffer,"time=%.2lf s\n\n",&time);
34    }
35    else
36    {
37        perror("failed!");
38    }
39    QString tempStr;
40    ui->lineEdit->setText(tempStr.setNum(time));
41 }


这是我编的一段代码,在windows下的Qtcreator中可以编译成功,但是在linux编译时出现错误,错误如下

timeread.cpp: In member function 'void TimeRead::readtime()':
timeread.cpp:34: error: assignment of function 'time_t time(time_t*)'
timeread.cpp:34: error: cannot convert 'double' to 'time_t(time_t*)throw ()' in assignment
timeread.cpp:36: warning: unknown conversion type character '.' in format
timeread.cpp:36: warning: too many arguments for format
timeread.cpp:43: error: call of overloaded 'setNum(time_t (&)(time_t*)throw ())' is ambiguous
各位大侠帮忙解决一下
快速回复
限100 字节
 
上一个 下一个