问题描述:http通信中,采用code1阻塞通信,等待通信返回数据,发现在一些密集型耗时操作(滑块处理事件) 处理不及时,导致滑动停止后还在处理,但是采用code2并不这样
// code 1
QEventLoop eventLoop;
connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
// code 2
QEventLoop eventLoop;
connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec();
两者的区别在在于:
eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
eventLoop.exec();//默认值QEventLoop::AllEvents
参数含义如下:
QEventLoop::AllEvents 0x00
All events. Note that DeferredDelete events are processed specially. See QObject::deleteLater() for more details.
QEventLoop::ExcludeUserInputEvents 0x01
Do not process user input events, such as ButtonPress and KeyPress. Note that the events are not discarded; they will be delivered the next time processEvents() is called without the ExcludeUserInputEvents flag.
QEventLoop::ExcludeSocketNotifiers 0x02
Do not process socket notifier events. Note that the events are not discarded; they will be delivered the next time processEvents() is called without the ExcludeSocketNotifiers flag.
QEventLoop::WaitForMoreEvents 0x04
Wait for events if no pending events are available.
QEventLoop::AllEvents 0x00
所有事件。 请注意,DeferredDelete 事件经过特殊处理。 有关更多详细信息,请参阅 QObject::deleteLater()。
QEventLoop::ExcludeUserInputEvents 0x01
不处理用户输入事件,例如 ButtonPress 和 KeyPress。 请注意,事件不会被丢弃; 它们将在下次调用 processEvents() 时不带 ExcludeUserInputEvents 标志时传递。
QEventLoop::ExcludeSocketNotifiers 0x02
不处理套接字通知程序事件。 请注意,事件不会被丢弃; 它们将在下次调用 processEvents() 而不带 ExcludeSocketNotifiers 标志时传送。
QEventLoop::WaitForMoreEvents 0x04
如果没有挂起的事件可用,则等待事件。
原因可能是code1不处理用户事件,但事件并不会被丢弃,导致事件堆积,所以滑动滑块停止后,还有很多事件没有处理完,导致还在处理,所以表现出很卡顿的现象