• 5175阅读
  • 2回复

was terminated due to signal code SIGILL [复制链接]

上一主题 下一主题
离线t1397018
 
只看楼主 倒序阅读 楼主  发表于: 2009-09-08
C/C++ code
//clock.h

#include<qapplication.h>
#include<qsound.h>
#include<qlabel.h>
#include<qdatetime.h>
#include<qstring.h>
#include<qnamespace.h>
#include<qfont.h>
#include<qtimer.h>
#include<qpushbutton.h>
#include<qvbox.h>
#include<qhbox.h>
#include<qlineedit.h>

#include<sys/ioctl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>

class Clock:public QWidget
{
    Q_OBJECT
    public:
       Clock(QWidget *parent=0,const char *name=0);
    public slots:
       void rePaintTime();
       void setBeepTime();
       void beep();
    signals:
       void timeOut();    
    private:
       QTime nowTime;  
       QString time;
       QLabel *label;
       QString beepTime;
       QLineEdit *textTime;
};
//clock.cpp
#include"clock.h"

Clock::Clock(QWidget *parent,const char *name):QWidget(parent,name)
{
   QVBox *vBox = new QVBox(this);
   QHBox *hBox = new QHBox(vBox);

   (void) new QLabel("Your Waik Time :",hBox);
   textTime = new QLineEdit(hBox);
   QPushButton *submit = new QPushButton("Submit",hBox);
   connect(submit,SIGNAL(clicked()),this,SLOT(setBeepTime()));
  
   label = new QLabel("",vBox);
   QTimer *timer = new QTimer(this);
   connect(timer,SIGNAL(timeout()),this,SLOT(rePaintTime()));
  
   label->resize(100,100);
   label->setFont(QFont("Times",18,QFont::Bold));
  
   nowTime = QTime::currentTime();
   time = nowTime.toString();
  
   label->setText(time);
  
   timer->start(1000,FALSE);
   connect(this,SIGNAL(timeOut()),this,SLOT(beep()));
}

void Clock::rePaintTime()
{
   nowTime = QTime::currentTime();
   time = nowTime.toString();
   if(time == beepTime) emit timeOut();
   label->setText(time);
}

void Clock::setBeepTime()
{
   beepTime = textTime->text();  
}

void Clock::beep()
{
   int fd;
   fd = open("/dev/beeps",0);
   if(fd < 0)
    {
       printf("Open /dev/beeps Failed\n");
       exit(1);
    }
   ioctl(fd,0,0);
   close(fd);
}
//main.cpp
#include"clock.h"

int main(int argc,char **argv)
{
   QApplication app(argc,argv);
   Clock clock;
   app.setMainWidget(&clock);
   clock.show();
   return app.exec();
}



程序的功能是一个简易的闹钟,读取系统时间,然后设置一个时间,时间一到就打开蜂鸣器。
窗口运行正常,但是,一旦运行beep()后就出现was terminated due to signal code SIGILL然后退出,但是蜂鸣器确实响了。我知道这是使用了非法地址出现的错误,但是我找不到我哪里非法了。在调用beep()以前运行正常。
求解
离线t1397018
只看该作者 1楼 发表于: 2009-09-08
自己顶起
离线t1397018
只看该作者 2楼 发表于: 2009-09-09
顶起
快速回复
限100 字节
 
上一个 下一个