标签:
Qt 定时器signal/slot阻塞主线程界面<span style="font-size:18px;">class bicycle : public QMainWindow
{
public slots:
void uploadDeviceStatus();
};
bicycle::bicycle(QWidget *parent) :
QMainWindow(parent)
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(uploadDeviceStatusSlot()));
timer->start(1000);
}
</span><span style="font-size:18px;">
class Sloter : public QObject
{
Q_OBJECT
public slots:
void uploadDeviceStatusSlot() { bicycle->uploadDeviceStatusSlot(); } // 这里调用bicycle中的函数
};
bicycle::bicycle(QWidget *parent) :
QMainWindow(parent)
{
QThread *thread = new QThread();
Sloter *sloter = new Sloter();
QTimer *timer = new QTimer(this);
sloter->moveToThread(thread); // 这里是关键
connect(timer, SIGNAL(timeout()), sloter, SLOT(uploadDeviceStatusSlot())); // 连接时,signal与Sloter的对象连接
timer->start(1000);
}</span>作者:帅得不敢出门 程序员群:31843264标签:
原文地址:http://blog.csdn.net/zmlovelx/article/details/43086791