我做了有两个控制按健PushButton的小应用程序,但在Arm开发板上一点击按钮就自动退出,不知道是怎么回事,
(驱动以测试过好用),请教原因:程序如下:
////////test.h/////////// /////
////// defined classsses////
#ifndef FORM1_H
#define FORM1_H
#include <qvariant.h>
#include <qdialog.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;
class Form1 : public QDialog
{
Q_OBJECT
public:
Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Form1();
QPushButton* PushButton1_1; //点击后LED亮
QPushButton* PushButton1_2; //点击后LED灭
QPushButton* PushButton1_3; //退出健
public slots:
virtual void On_slot(); //LED_on SLOT
virtual void Off_slot(); //LED_OFF SLOT
private:
char led; //LED status
int fd;
};
#endif // FORM1_H
///////////test.cpp/////////////////////
#include "test.h"
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
/*
* Constructs a Form1 which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "Form1" );
resize( 450, 325 );
setCaption( tr( "Led" ) );
int led0=0;
int fd1;
static char *dev_name1="/dev/keypad1";
fd1=open(dev_name1,O_RDWR);
write(fd1,(const char*)&led0,sizeof((const char)led0));
close(fd1);
PushButton1_1 = new QPushButton( this, "PushButton1_1" );
PushButton1_1->setGeometry( QRect( 80, 100, 120, 35 ) );
PushButton1_1->setText( tr( "Turn on" ) );
PushButton1_2 = new QPushButton( this, "PushButton1_2" );
PushButton1_2->setGeometry( QRect( 250, 100, 120, 35 ) );
PushButton1_2->setText( tr( "Turn off" ) );
PushButton1_3 = new QPushButton( this, "PushButton1_3" );
PushButton1_3->setGeometry( QRect( 170, 190, 120, 35 ) );
PushButton1_3->setText( tr( "Exit" ) );
// signals and slots connections
connect( PushButton1_1, SIGNAL( clicked() ), this, SLOT( On_slot() ) );
connect( PushButton1_2, SIGNAL( clicked() ), this, SLOT( Off_slot() ) );
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
void Form1::On_slot() /// operation to trun on the led
{
// qWarning( "Form1::On_slot(): Not implemented yet!" );
led=1;
static char *dev_name="/dev/keypad1";
fd=open(dev_name,O_RDWR);
write(fd,(const char*)&led,sizeof((const char)led));
close(fd);
}
void Form1::Off_slot() /// operation to trun off the led
{
// qWarning( "Form1::Off_slot(): Not implemented yet!" );
led=0;
static char *dev_name="/dev/keypad1";
fd=open(dev_name,O_RDWR);
write(fd,(const char*)&led,sizeof((const char)led));
close(fd);
}
///////////main.cpp//////////////////////
#include "test.h"
#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>
int main(int argc,char **argv)
{
QApplication a(argc,argv);
Form1 w;
a.setMainWidget(&w);
w.show();
return a.exec();
}