资源描述:
《qt串口操作例程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、[mainwindow.cpp]#include #include #include #include#include#include#include#include#include#include"mainwindow.h" #include"serialthread.h" voidMa
2、inWindow::paintEvent(QPaintEvent*){ QPainterpaint(this); paint.drawLine(0,0,500,500);//drawline paint.drawPixmap(0,0,*pix); }voidMainWindow::loadJPEGFile(){ if(!pix->load("testjpeg")){ //if(!pix->load("circle")){ setMsgText("Loadfailed");
3、 return; } setMsgText("Loadsuccess!"); update(); }voidMainWindow::setCounter(intno){ counter=no;}voidMainWindow::serialOperate(){ a=newSerialThread(this); a->start(); a->wait();}MainWindow::MainWindow(QWidget*parent,constchar*name) :QMainWindow(
4、parent,name){ counter=0; QVBox*vbox; vbox=newQVBox(this); vbox->resize(300,150); //msg=newQLabel("SERIALPROGRAMMING",vbox); msg=newQLineEdit("SERIALPROGRAMMING",vbox); msg->resize(300,50); pix=new QPixmap();
5、 btn=newQPushButton(vbox); btn->setText("GO!"); QApplication::connect(btn,SIGNAL(clicked()),this,SLOT(serialOperate())); btn2LoadImg=newQPushButton(vbox); btn2LoadImg->setText("LOAD"); lab=newQLabel("beforeloadjpeg",vbox); QApplicatio
6、n::connect(btn2LoadImg,SIGNAL(clicked()),this,SLOT(loadJPEGFile())); //btn->resize(100,75); //vbox->show();};voidMainWindow::setMsgText(char*txt){ QStringmsgs(txt); QStringcount=QString::number(counter,10); msgs.append(count); const
7、char*re=msgs.ascii(); //strcat(msgs,); msg->setText(re); };[my_define.h]#defineBAUDRATE B115200#defineBLOCK_SIZE 200 #defineDEVICE "/dev/ttyS0"#defineWAIT_TIME 5#defineCHANGE_LINE 0x0a#defineACK_NUM 3#ifndefTRUE#defineTRUE1#endif#ifnd
8、efFALSE#defineFALSE-1#endif[serialthread.h]#ifndefSERIAL_THREAD_H#define SERIAL_THREAD_H#includeclassMainWindow;classSerialThread:publicQThread{public: SerialThread(MainWindow*parent); virtualvoi