API meaning: qcoreapplication::processevents() will process all events in the event queue and return it to the caller.
Problem Description:
When the main thread is executing processevents in a slot function, there is just one signal that can respond to this slot function (which is definitely the signal of the other line Cheng), and a terrible recursion may occur.
Causes a stack overflow to crash. The reason is processevents, into the endless recursion.
Example code:
BugThread.h
#include <qthread>class bugthread:public qthread{q_objectpublic:bugthread (qobject* parent): QThread (parent) {} Signals:void sigbugsignal ();p ublic:void run () {while (true) {Emit sigbugsignal ()}};
Bugs.h & Bugs.cpp
Class Bugs:public qmainwindow{q_objectpublic:bugs (Qwidget *parent = 0, Qt::wflags flags = 0); ~bugs ();p ublic slots:void o Nbugslot ();p rivate:ui::bugsclass Ui;}; Bugs::bugs (Qwidget *parent, Qt::wflags flags): Qmainwindow (parent, flags) {UI.SETUPUI (this); bugthread* BT = new Bugthread (this), connect (BT, SIGNAL (Sigbugsignal ()), this, SLOT (Onbugslot ())); Bt->start ();} Bugs::~bugs () {}void bugs::onbugslot () {Sleep (1); Qapplication::processevents();}
QT Learning Series [9]–qcoreapplication:processevents () may cause recursion, causing stack overflow to crash