⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.cpp

📁 qtopia的串口通信程序
💻 CPP
字号:
#include <qlabel.h>      
#include <qpushbutton.h>  
#include <QVBoxLayout>  
#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("test.jpeg")){
		//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) : QMainWindow(parent) 
{ 
    
	counter = 0; 
	QVBoxLayout *vbox;
	vbox = new QVBoxLayout(this);
	msg = new QLineEdit("SERIAL PROGRAMMING",this); 
	msg->resize(50,50);
	vbox->addWidget(msg);
	pix = new QPixmap();              
	
	btn = new QPushButton(this); 
	btn->setText("GO!");	vbox->addWidget(btn);
	QApplication::connect(btn,SIGNAL(clicked()),this,SLOT(serialOperate()));
	btn2LoadImg = new QPushButton(this);
	btn2LoadImg->setText("LOAD");	vbox->addWidget(btn2LoadImg);
	
	lab = new QLabel("before load jpeg");	vbox->addWidget(lab);
	QApplication::connect(btn2LoadImg,SIGNAL(clicked()),this,SLOT(loadJPEGFile())); 
	
	//btn->resize(100,75); 
}; 

void MainWindow::setMsgText(char* txt){ 
	QString msgs(txt); 
	QString count = QString::number(counter,10); 
	msgs.append(count); 
	const char *re = msgs.toAscii ();          
	//strcat(msgs,); 
	msg->setText(re);    
};

⌨️ 快捷键说明

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