2022年QT串口编程 .pdf
《2022年QT串口编程 .pdf》由会员分享,可在线阅读,更多相关《2022年QT串口编程 .pdf(7页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、QT串口编程 .txt都是一个山的狐狸,你跟我讲什么聊斋,站在离你最近的地方,眺望你对别人的微笑,即使心是百般的疼痛只为把你的一举一动尽收眼底刺眼的白色,让我明白什么是纯粹的伤害。QT串口编程serial.cpp #include #include #include mainwindow.h int main(int argc, char *argv) QApplication a(argc,argv); MainWindow m; a.setMainWidget(&m); m.show(); return a.exec(); mainwindow.h #ifndef MAIN_WINDOW_
2、H #define MAIN_WINDOW_H #include class QLabel; class QPushButton; class QLineEdit; class QPixmap; class SerialThread; class MainWindow:public QMainWindow Q_OBJECT public: MainWindow(QWidget * parent = 0, const char * name= 0) ; MainWindow(); void setCounter(int no); void setMsgText(char* txt); publi
3、c slots: void serialOperate(); void loadJPEGFile(); protected: void paintEvent( QPaintEvent * ); private: 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - QLineEdit *msg; QPushButton *btn; QPushButton *btn2LoadImg; QPixmap *pix; QLabel *lab;
4、 SerialThread *a; int counter; ; #endif mainwindow.cpp #include #include #include #include #include #include #include #include #include #include mainwindow.h #include serialthread.h void MainWindow:paintEvent( QPaintEvent * ) QPainter paint( this ); paint.drawLine( 0,0,500,500 ); / draw line paint.d
5、rawPixmap(0,0,*pix); void MainWindow:loadJPEGFile() if(!pix-load(testjpeg) /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(); 名师资料总结 - - -精
6、品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - 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
7、,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 l
8、oad 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,); ms
9、g-setText(re); ; my_define.h #define BAUDRATE B115200 #define BLOCK_SIZE 200 #define DEVICE /dev/ttyS0 #define WAIT_TIME 5 #define CHANGE_LINE 0 x0a 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - #define ACK_NUM 3 #ifndef TRUE #define TRUE
10、 1 #endif #ifndef FALSE #define FALSE -1 #endif serialthread.h #ifndef SERIAL_THREAD_H #define SERIAL_THREAD_H #include class MainWindow; class SerialThread: public QThread public: SerialThread(MainWindow *parent); virtual void run(); private: MainWindow *parent; ; #endif serialthread.cpp #include #
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年QT串口编程 2022 QT 串口 编程
限制150内