mainwindow.cpp

来自「基于qt的串口多线程编程」· C++ 代码 · 共 79 行

CPP
79
字号
#include <qlabel.h>     #include <qpushbutton.h>  #include <qvbox.h> #include <qapplication.h>#include <qlineedit.h>#include <qpixmap.h>#include <qpainter.h>#include <qimage.h>#include <qstring.h>  #include "mainwindow.h"   #include "serialthread.h"     void MainWindow::paintEvent( QPaintEvent * ){    QPainter paint( this );    paint.drawLine( 0,0,500,500 ); // draw line        paint.drawPixmap(0,0,*pix);        } void MainWindow::loadJPEGFile(){          if(!pix->load("/root/serial/bin/1.JPG")){     //if(!pix->load("circle")){         setMsgText("Load failed");        return;     }    setMsgText("Load success!");    update();         } void MainWindow::setCounter(int no){    counter = no;} void MainWindow::serialOperate(){  a = new SerialThread(this);    a->start();    a->wait();} MainWindow::MainWindow(QWidget * parent , const char * name)    :QMainWindow(parent, name){             counter = 0;                 QVBox *vbox;        vbox = new QVBox(this);        vbox->resize(300,150);        //msg = new QLabel("SERIAL PROGRAMMING",vbox);        msg = new QLineEdit("SERIAL PROGRAMMING",vbox);        msg->resize(300,50);                 pix = new    QPixmap();                               btn = new QPushButton(vbox);        btn->setText("GO!");        QApplication::connect(btn,SIGNAL(clicked()),this,SLOT(serialOperate()));        btn2LoadImg = new QPushButton(vbox);        btn2LoadImg->setText("LOAD");                 lab = new QLabel("before load jpeg",vbox);        QApplication::connect(btn2LoadImg,SIGNAL(clicked()),this,SLOT(loadJPEGFile()));                 //btn->resize(100,75);        //vbox->show();}; void MainWindow::setMsgText(char* txt){        QString msgs(txt);        QString count = QString::number(counter,10);        msgs.append(count);        const     char *re = msgs.ascii ();                  //strcat(msgs,);        msg->setText(re);     };

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?