环境:板子为2410,arm-gcc-3.3.2 QTE2.3.7
以下为mainwindow.cpp
#include "mainwindow.h"
#include "my_define.h"
#include "serialthread.h"
MyMainWindow :: MyMainWindow()
{
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd<0)
printf("open %s fail %d\n",MODEMDEVICE,fd);
else
printf("open %s success %d\n",MODEMDEVICE,fd);
//a = new SerialThread(this);
setGeometry(0,0,320,240);
//this->setMinimumSize(320,240);
//this->setMaximumSize(320,240);
QPixmap image("background.jpg");
setBackgroundPixmap(image);
//这个地方没有起作用呀 b1=new QPushButton("verygood",this);
QPalette newPalette=b1->palette();
newPalette.setColor(QColorGroup::ButtonText, Qt::red);
b1->setPalette(newPalette);
b1->setGeometry(30,140,120,40);
b1->setFont(QFont("Times",18,QFont::Bold));
b2=new QPushButton("yibangood",this);
QPalette pal = b2->palette();
pal.setColor(QColorGroup::Button, Qt::blue);
b2->setPalette(pal);
b2->setGeometry(180,140,120,40);
b2->setFont(QFont("Times",18,QFont::Bold));
b3=new QPushButton("bad1",this);
b3->setGeometry(30,190,50,40);
b3->setFont(QFont("Times",18,QFont::Bold));
b4=new QPushButton("bad2",this);
b4->setGeometry(100,190,50,40);
b4->setFont(QFont("Times",18,QFont::Bold));
b5=new QPushButton("bad3",this);
b5->setGeometry(180,190,50,40);
b5->setFont(QFont("Times",18,QFont::Bold));
b6=new QPushButton("bad4",this);
b6->setGeometry(250,190,50,40);
b6->setFont(QFont("Times",18,QFont::Bold));
/*QVBoxLayout *vbox =new QVBoxLayout(this);
QHBoxLayout *hbox1 =new QHBoxLayout();
QHBoxLayout *hbox2 =new QHBoxLayout();
vbox->addLayout(hbox1);
vbox->addLayout(hbox2);
hbox1->addWidget(b1);
hbox1->addWidget(b2);
hbox2->addWidget(b3);
hbox2->addWidget(b4);
hbox2->addWidget(b5);
hbox2->addWidget(b6);*/
connect(b1,SIGNAL(clicked()),this,SLOT(sendverygood()));
connect(b2,SIGNAL(clicked()),this,SLOT(sendgood()));
connect(b3,SIGNAL(clicked()),this,SLOT(sendbad1()));
connect(b4,SIGNAL(clicked()),this,SLOT(sendbad2()));
connect(b5,SIGNAL(clicked()),this,SLOT(sendbad3()));
connect(b6,SIGNAL(clicked()),this,SLOT(sendbad4()));
//label=new QLabel(this);
//label->setGeometry(10,110,150,50);
//label->setText("If you click the button above,\n the whole program will exit");
}
void MyMainWindow::paintEvent(QPaintEvent *)
//这个地方也没有起作用呀{
QPixmap image("zhiye.jpg");
QPainter paint;
paint.begin(this);
paint.drawPixmap(20,13,image);
paint.end();
}
void playxiexie()
{
QSound bells("/test/xiexie.wav");
bells.play();
}
void playnihao()
{
QSound bells("/test/nihao.wav");
bells.play();
}
void playfuwu()
{
QSound bells("/test/fuwu.wav");
bells.play();
}
void MyMainWindow::sendverygood()
{
char buf[]={'v','e','r','y','g','o','o','d',CHANGE_LINE};
write(fd,buf,sizeof(buf));
QSound bells("/test/xiexie.wav");
bells.play();
//a->start();
//a->wait();
}
void MyMainWindow::sendgood()
{
char buf[]={'y','i','b','a','n','g','o','o','d',CHANGE_LINE};
write(fd,buf,sizeof(buf));
playxiexie();
//a->stop();
/*if(QSound::available()== true)
{
//printf("it's available\n");
QSound bells("/test/xiexie.wav");
bells.play();
}
else
{
//printf("not available\n");
}
system("madplay /test/xingkong.mp3");*/
}
void MyMainWindow::sendbad1()
{
char buf[]={'b','a','d','1',CHANGE_LINE};
write(fd,buf,sizeof(buf));
playxiexie();
}
void MyMainWindow::sendbad2()
{
char buf[]={'b','a','d','2',CHANGE_LINE};
write(fd,buf,sizeof(buf));
playxiexie();
}
void MyMainWindow::sendbad3()
{
char buf[]={'b','a','d','3',CHANGE_LINE};
write(fd,buf,sizeof(buf));
playxiexie();
}
void MyMainWindow::sendbad4()
{
char buf[]={'b','a','d','4',CHANGE_LINE};
write(fd,buf,sizeof(buf));
playxiexie();
}
以下为"mainwindow.h"
#ifndef __MAIN_WINDOW_H
#define __MAIN_WINDOW_H
#include <qwidget.h>
#include <qsound.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlabel.h>
#include <qlcdnumber.h>
#include <qslider.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qlayout.h>
//class SerialThread;
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
MyMainWindow();
~MyMainWindow(){};
int fd;
public slots:
void sendverygood();
void sendgood();
void sendbad1();
void sendbad2();
void sendbad3();
void sendbad4();
//void loadJPEGFile();
protected:
void paintEvent(QPaintEvent *);
private:
QLabel *name;
QLabel *num;
QPushButton *b1;
QPushButton *b2;
QPushButton *b3;
QPushButton *b4;
QPushButton *b5;
QPushButton *b6;
//SerialThread *a;
};
#endif
[ 此帖被wandersky在2009-09-07 18:06重新编辑 ]