当前位置: 代码迷 >> QT开发 >> <>Qt:为什么小弟我这个函数一执行就有段异常
  详细解决方案

<>Qt:为什么小弟我这个函数一执行就有段异常

热度:10   发布时间:2016-04-25 04:21:56.0
<急>Qt:为什么我这个函数一执行就有段错误
/************************dialog.h*********************/
#include <QApplication>
#include <QPushButton>
#include<QWidget>
#include<QtGui>

class Dialogs : public QWidget
{
    Q_OBJECT
public:
    Dialogs();
public:
    QFrame *frame;
    QPushButton * button0; 
    QPushButton * button1 ;
    QPushButton * button2 ;
private slots:
    void slotbutton0();
    void slotbutton1();
   // void slotbutton2();
};
/************************dialog.cpp*********************/
#include <QApplication>
#include<stdio.h>
#include<unistd.h>
#include <QtGui>
#include"dialog.h"
int pid;

Dialogs::Dialogs( )
   
{  
   frame->setObjectName("myframe");
   frame->resize(320,240); 
   frame->setStyleSheet("QFrame#myframe{border-image:url(images/background.png)}" );

   button0->setGeometry(260,30,50,50);
   button1->setGeometry(260,90,50,50);
   button2->setGeometry(260,150,50,50);

   QIcon icon;
   QPixmap pixmap0("images/Start_amended.png");
   icon.addPixmap(pixmap0);
   button0->setIcon(icon);
   button0->setIconSize(QSize(68,68));
   button0->setFixedSize(pixmap0.size());
   button0->setMask(pixmap0.mask());


   QPixmap pixmap1("images/Stop_amended.png");
   icon.addPixmap(pixmap1);
   button1->setIcon(icon);
   button1->setIconSize(QSize(50,50));
   button1->setFixedSize(pixmap1.size());
   button1->setMask(pixmap1.mask());


   QPixmap pixmap2("images/set.png");
   icon.addPixmap(pixmap2);
   button2->setIcon(icon);
   button2->setIconSize(QSize(50,50));
   button2->setFixedSize(pixmap2.size());
   button2->setMask(pixmap2.mask());
   
   connect(button0,SIGNAL(clicked()),this,SLOT(slotbutton0()));
   connect(button1,SIGNAL(clicked()),this,SLOT(slotbutton1()));
   
}
void Dialogs::slotbutton0()
{                              
  execlp("sh","sh","hello.sh",NULL);
  pid=getpid();       
}    

void Dialogs::slotbutton1()
{                              
  char a[10];
  sprintf(a,"%s",pid);
  execlp("kill","kill",a,NULL);    
}            
/************************main.cpp*********************/
#include <QApplication>
#include<stdio.h>
#include<unistd.h>
#include <QtGui>
#include"dialog.h"

int main( int argc, char **argv )
  相关解决方案