- 论坛徽章:
- 0
|
本帖最后由 心染红尘 于 2015-04-22 20:35 编辑
设计的程序在mini2440开发板执行,程序自行终止,这是为什么?
程序如下:- #ifndef MOTOR_H
- #define MOTOR_H
- #include<qobject.h>
- class Motor : public QObject
- {
- Q_OBJECT
- public:
- explicit Motor(QObject *parent=0);
- public:
- int fd;
- int on[3];
- public:
- ~Motor();
- public:
- void motor1_on();
- void motor2_on();
- void motor3_on();
- void motor2_off();
- };
- #endif // MOTOR_H
复制代码
- #include"motor.h"
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<stdio.h>
- #include<sys/ioctl.h>
- #include<stdlib.h>
- #include<unistd.h>
- Motor::Motor(QObject *parent):
- QObject(parent)
- {
- on[0]=0;
- on[1]=0;
- on[2]=0;
- fd=open("/dev/motor",0);
- if(fd<0)
- {
- perror("Error:fd<0");
- }
- }
- void Motor::motor1_on()
- {
- on[0]=(~on[0])&1;
- ioctl(fd,on[0],0);
- }
- void Motor::motor2_on()
- {
- on[1]=(~on[1])&1;
- ioctl(fd,on[1],1);
- }
- void Motor::motor3_on()
- {
- on[2]=(~on[2])&1;
- ioctl(fd,on[2],2);
- }
- void Motor::motor2_off()
- {
- on[1]=(on[1])&1;
- ioctl(fd,on[1],1);
- }
- Motor::~Motor()
- {
- }
复制代码- /****************************************************************************
- ** Form interface generated from reading ui file 'motordialog.ui'
- **
- ** Created by User Interface Compiler
- **
- ** WARNING! All changes made in this file will be lost!
- ****************************************************************************/
- #ifndef MOTORDIALOG_H
- #define MOTORDIALOG_H
- #include <qvariant.h>
- #include <qwidget.h>
- #include "motor.h"
- #include <cstdlib>
- class QVBoxLayout;
- class QHBoxLayout;
- class QGridLayout;
- class QSpacerItem;
- class QPushButton;
- class motordialog : public QWidget
- {
- Q_OBJECT
- public:
- motordialog( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
- ~motordialog();
- QPushButton* pushButton1;
- QPushButton* pushButton2;
- QPushButton* pushButton3;
- Motor* motor_PP;
- Motor* motor_NP;
- Motor* motor_SON;
- public slots:
- virtual void motor_start();
- virtual void motor_stop();
- virtual void motor_exit();
- virtual void motor_delay(int times);
- protected:
- protected slots:
- virtual void languageChange();
- };
- #endif // MOTORDIALOG_H
复制代码- /****************************************************************************
- ** Form implementation generated from reading ui file 'motordialog.ui'
- **
- ** Created by User Interface Compiler
- **
- ** WARNING! All changes made in this file will be lost!
- ****************************************************************************/
- #include "motordialog.h"
- #include <qvariant.h>
- #include <qpushbutton.h>
- #include <qlayout.h>
- #include <qtooltip.h>
- #include <qwhatsthis.h>
- /*
- * Constructs a motordialog as a child of 'parent', with the
- * name 'name' and widget flags set to 'f'.
- */
- motordialog::motordialog( QWidget* parent, const char* name, WFlags fl )
- : QWidget( parent, name, fl )
- {
- if ( !name )
- setName( "motordialog" );
- setMaximumSize( QSize( 240, 320 ) );
- pushButton1 = new QPushButton( this, "pushButton1" );
- pushButton1->setGeometry( QRect( 40, 60, 131, 31 ) );
- pushButton2 = new QPushButton( this, "pushButton2" );
- pushButton2->setGeometry( QRect( 40, 150, 131, 31 ) );
- pushButton3 = new QPushButton( this, "pushButton3" );
- pushButton3->setGeometry( QRect( 40, 240, 131, 31 ) );
- languageChange();
- resize( QSize(240, 320).expandedTo(minimumSizeHint()) );
- clearWState( WState_Polished );
- // signals and slots connections
- connect( pushButton1, SIGNAL( clicked() ), this, SLOT( motor_start() ) );
- connect( pushButton2, SIGNAL( clicked() ), this, SLOT( motor_stop() ) );
- connect( pushButton3, SIGNAL( clicked() ), this, SLOT( motor_exit() ) );
- }
- /*
- * Destroys the object and frees any allocated resources
- */
- motordialog::~motordialog()
- {
- // no need to delete child widgets, Qt does it all for us
- }
- /*
- * Sets the strings of the subwidgets using the current
- * language.
- */
- void motordialog::languageChange()
- {
- setCaption( tr( "MotorControl" ) );
- pushButton1->setText( tr( "START" ) );
- pushButton2->setText( tr( "STOP" ) );
- pushButton3->setText( tr( "EXIT" ) );
- }
- void motordialog::motor_start()
- {
- //qWarning( "motordialog::motor_start(): Not implemented yet" );
- motor_SON->motor1_on();
- // motor_NP->motor3_on();
- int m=10000;
- while(m)
- {
- m--;
- motor_PP->motor2_on();
- motor_delay(1000);
- motor_PP->motor2_off();
- motor_delay(1000);
- }
- }
- void motordialog::motor_stop()
- {
- //qWarning( "motordialog::motor_stop(): Not implemented yet" );
- motor_SON->motor1_on();
- motor_PP->motor2_off();
- }
- void motordialog::motor_exit()
- {
- //qWarning( "motordialog::motor_exit(): Not implemented yet" );
- exit(0);
- }
- void motordialog::motor_delay(int times)
- {
- int i;
- int j;
- for(i=0;i<times;i++)
- {
- for(j=0;j<times;j++)
- {
- }
- }
- }
复制代码 点击START,出现以下错误
|
|