Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an event loop in Qt?

I have understood the following regarding QApplication's exec function:

QApplication exec starts the main event loop. It launches the GUI. It processes the signals and calls appropriate slots on receiving them. It waits until exit is called and returns the value which was set in exit.

Now, when we say event loop, does it mean that there is some while loop running in the internal code of Qt, and in that while loop the method of handling signals and slots is written?

like image 780
Aquarius_Girl Avatar asked Nov 30 '16 05:11

Aquarius_Girl


People also ask

How Qt signals and slots work?

In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.

Is QObject thread-safe?

QObject and all of its subclasses are not thread-safe. This includes the entire event delivery system.

Does Qthread have an event loop?

QThreads begin executing in run(). By default, run() starts the event loop by calling exec() and runs a Qt event loop inside the thread. You can use worker objects by moving them to the thread using QObject::moveToThread().

What is event loop C?

An event loop is often the main loop in a program that typically waits for the user to trigger something. The following example is the main loop in the first software engine for this encyclopedia. Written in Turbo C, the main loop is constantly testing for menu selections, keystrokes and mouse clicks.


1 Answers

Now, when we say event loop, does it mean that there is some while loop running in the internal code of Qt, and in that while loop the method of handling signals and slots is written?

In a sense, yes. Most software these days sits and waits for events -- user input, network traffic, timer events, sensors, etc. -- and responds accordingly.

This is not specific to Qt. It's a common design pattern you'll find everywhere from Windows to Android to Arduino.

like image 76
MrEricSir Avatar answered Sep 29 '22 08:09

MrEricSir