QT中难以解决的问题
/********************dialog.h****************************/
#include <QApplication>
#include<QWidget>
#include<QtGui>
#include"printtext.h"
class Dialogs : public QWidget
{
Q_OBJECT
public:
Dialogs();
private:
QFrame *frame;
QPushButton *button0;
QPushButton *button1;
QPushButton *button2;
QTextEdit *textEdit;
private slots:
void slotbutton0();
void slotbutton1();
void slotbutton2();
// void slotbutton3();
};
/********************dialog.cpp****************************/
#include <QApplication>
#include<stdio.h>
#include<unistd.h>
#include <QtGui>
#include"printtext.h"
#include"dialog.h"
QFile file("printer.txt");
int pid;
Dialogs:ialogs( )
{
frame=new QFrame(this);
button0=new QPushButton(this);
button1=new QPushButton(this);
button2=new QPushButton(this);
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(50,50));
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()));
connect(button2,SIGNAL(clicked()),this,SLOT(slotbutton2()));
// connect(button3,SIGNAL(clicked()),this,SLOT(slotbutton3()));
}
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);
}
void Dialogs::slotbutton2()
{
// QWidget *w1=new QWidget;
textEdit=new QTextEdit(this);
// w1->addwidget(textEdit,0,0);
if(file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QTextStream textStream(&file);
while(!textStream.atEnd())
{
textEdit->append(textStream.readLine());
}
file.close();
textEdit->show();
}
}
//void Dialogs::slotbutton3()
//{
// QTextStream out(&file);
// out<<textEdit->toPlainText();
// file.close();
//}
/********************main.cpp****************************/
#include <QApplication>
#include<stdio.h>
#include<unistd.h>
#include <QtGui>
#include"dialog.h"
int main( int argc, char **argv )
{
QApplication a( argc, argv );
Dialogs *dialogs = new Dialogs();
// Dialogs *dialogs;
dialogs->show();
return a.exec();
}