更新时间:2022-08-12 20:28:49
/******************************************************************* * a demo for how to use QThread * 声明: * 这是一个简单的QThread使用模板,对于应付简单的程序来说, * 还是足够了。 * * 2015-9-12 阴 深圳 南山平山村 曾剑锋 ******************************************************************/ cat thread.h #ifndef THREAD_H #define THREAD_H #include <QThread> class Thread : public QThread { Q_OBJECT public: explicit Thread(QObject *parent = 0); signals: void msg(QString str); public slots: void run(); void stop(); private: bool running; }; #endif // THREAD_H cat thread.c #include "thread.h" Thread::Thread(QObject *parent) : QThread(parent) { running = true; } void Thread::run() { int nbytes; int len; struct can_frame frame; struct sockaddr_can addr; char buf[10]; while(running) { QThread::msleep(100); /** * this was very important sametime for receive data */ if (running) { emit msg(QString(buf)); } } } void Thread::stop() { running = false; } cat mainwindow.c ...... /** * how to stop a Qt thread */ if ( thread != NULL ) { thread->stop(); thread->wait(); thread->deleteLater(); } ......
编写高质量代码改善java程序的151个建议——[52-57]String !about String How to use them?
How to use ASMCA in silent mode to configure ASM for a stand-alone server [ID 1068788.1]
轮廓的查找、表达、绘制、特性及匹配(How to Use Contour? Find, Component, Construct, Features & Match)
FAQ: How to Use AWR reports to Diagnose Database Performance Issues [ID 1359094.1]