thread2 和thread1 基本相同
#ifndef PAINT_H
#define PAINT_H
#include <qwidget.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include "Thread1.h"
#include "Thread2.h"
class paint: public QWidget
{
Q_OBJECT
public:
paint(QWidget *parent=0 , const char *name=0 );
protected:
virtual void paintEvent(QPaintEvent *);
public slots:
void changeA1( );
void changeA2( );
void changeB1( );
private :
QLabel *label1 ;
QLabel *label2 ;
QLabel *labelA1 ;
QLabel *labelA2 ;
QLabel *labelB1 ;
Thread1 threadA ;
Thread2 threadB ;
QPushButton *quitButton ;
QTime tim ;
int flag ;
};
#endif
////////////////////////////////////////////////////////////////////////////////
//////paint.cpp
#include <qapplication.h>
#include <qpainter.h>
#include <qlayout.h>
#include <qtextcodec.h>
#include <qpushbutton.h>
#include <qdatetime.h>
#include "paint.h"
struct paintstruct{
//QString name ;
Qt::PenStyle style ;
}
pstyle={ Qt::SolidLine};
int main(int argc ,char **argv)
{
QApplication app(argc ,argv ,"paint");
paint paint ;
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
paint.show();
app.setMainWidget(&paint);
return(app.exec());
}
paint::paint(QWidget *parent ,const char *name):QWidget(parent ,name)
{
setFixedSize(640,480);
label1 = new QLabel(threadA.time(), this);
label1->setGeometry(280,30,28,28);
label1->setAlignment(AlignVCenter | AlignHCenter);
label2 = new QLabel(threadB.time(), this);
label2->setGeometry(380,30,28,28);
label2->setAlignment(AlignVCenter | AlignHCenter);
quitButton = new QPushButton(tr("Quit"), this);
quitButton->setGeometry( 560, 430, 70, 30 );
quitButton->setDefault(true);
QObject::connect(quitButton, SIGNAL(clicked()),this, SLOT(close()));
flag=0; // 0:关 ,1:开
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
QString stringA("A 路");
QPushButton *buttonA = new QPushButton(stringA,this);
buttonA->setGeometry( 560, 30, 70, 30 );
connect(buttonA,SIGNAL(clicked()),qApp,SLOT(quit()));
QString stringA1("A 1");
QPushButton *buttonA1 = new QPushButton(stringA1,this);
buttonA1->setGeometry( 570, 80, 50, 30 );
labelA1 = new QLabel("关", this);
labelA1->setGeometry(70,265,28,28);
labelA1->setAlignment(AlignVCenter | AlignHCenter);
QObject::connect(buttonA1,SIGNAL(clicked()),this,SLOT(changeA1()));
QString stringA2("A 2");
QPushButton *buttonA2 = new QPushButton(stringA2,this);
buttonA2->setGeometry( 570, 130, 50, 30 );
labelA2 = new QLabel("开", this);
labelA2->setGeometry(150,265,28,28);
labelA2->setAlignment(AlignVCenter | AlignHCenter);
QObject::connect(buttonA2,SIGNAL(clicked()),this,SLOT(changeA2()));
QString stringB("B 路");
QPushButton *buttonB = new QPushButton(stringB,this);
buttonB->setGeometry( 560, 250, 70, 30 );
connect(buttonB,SIGNAL(clicked()),qApp,SLOT(quit()));
QString stringB1("B 1");
QPushButton *buttonB1 = new QPushButton(stringB1,this);
buttonB1->setGeometry( 570, 300, 50, 30 );
labelB1 = new QLabel("关", this);
labelB1->setGeometry(330,265,28,28);
labelB1->setAlignment(AlignVCenter | AlignHCenter);
QObject::connect(buttonB1,SIGNAL(clicked()),this,SLOT(changeB1()));
}
void paint::changeA1(){................}
void paint::paintEvent(QPaintEvent *)
{....................}
每次只能显示每个线程的一个数据 ,在控制台和我画的窗口中都是这样.那位做过这样的程序
帮帮忙呀, 现谢了!