Can QTimer fire when the queue is not empty? - qt

If there are both overdue QTimer-s and events waiting in event queue, what will QT dispatcher do? Fire the timers and run functions connected to them, or process events? In other words, can a timer fire when the event queue is not empty?

A QTimer firing is an event. See:
https://doc.qt.io/qt-5/qobject.html#timerEvent
Timer events are processed together with all the other events. QTimer is just a nice API around timer events, so that you don't have to deal with them manually. The QTimer class takes care of that for you.

Related

Different handlers for ejb Timer

I'm trying to set different handlers for different types of tasks created via TimerService , ejb.
I need to figure out a way where I can create a schedule tasks with extra information including the handler type so when a timeout occurs different handlers should be fired according to the timer identification.
Eventually the solution to the problem as i tried to explain is by adding Serialized handler, which is set when you create a timer event.
after you set a handler you can get it from the timer object, so when a timeout occurs we can execute an action according to the relevant handler.

Are KEY_TYPED events consumed by jxbrowser?

I've added a key listener to a jxbrowser 6.11 BrowserView object to log keys typed by the user. With this listener, I can see keyPressed and keyReleased events, but no keyTyped events. Could jxbrowser be consuming the KEY_TYPED events for some reason? And, if so, is there anything I can do about it? Unfortunately, because of restrictions in the external method being used to process and log the key events, it has to be a KEY_TYPED event passed to it.
KEY_TYPED event is processed properly in BrowserView for Browser instance that was created in LIGHTWEIGHT mode.

How QEventLoop must be used when we don't subclass QThread in Qt 4.8x?

I've read there are two approaches for working with QThread.
If I have a Worker class, which inherits QObject (as in http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/), then how should I create and manage local QEventLoop for working with signals/slots? I don't want to have memory leaks.
How QNetworkAccessManager should be created in worker described in http://codethis.wordpress.com/2011/04/04/using-qthread-without-subclassing/?
If you don't subclass QThread, it has its own event loop (Fixed QThread documentation of Qt 5, also appliccable for Qt 4):
By default, run() starts the event loop by calling exec() and runs a Qt event loop inside the thread.
Managing the work done by the worker can be easily done using signals & slots:
(...) you are free to connect the Worker's slots to any signal, from any object, in any thread. It is safe to connect signals and slots across different threads, thanks to a mechanism called queued connections.
This means you usually don't need to care about any event loop on your own (unless you require special behaviour). Simply connect the thread's started signal to any slot of your worker object and make sure you set up some kind of deletion chain: Either the worker emits a signal which leads to the thread being stopped and deleted, or the other way round - both ways work, depending on your situation.

Understanding how netty works

I'm trying to understand how netty works, and after reading some of the documentation I was to see if I understood how things work at a high level.
Basically netty has an event cycle, so whenever you make a call it gets serialized and the request gets pushed down to the o/s level, and it uses epoll and waits for an event to send back to netty.
When the operation system generates an event that netty subscribed to, netty then has an event loop that gets triggered.
Now the interested part here is, the event that gets triggered has to be parsed, and the client code (or custom code) has to figure out who actually this event is for.
So for example, if this was for a chat application, when a message is sent, it is up to the client code to figure out to send this message via ajax to the correct user.
Is this, at a high level, a correct overview of how netty works?
BTW, when netty listens for events sent via epoll, is this event loop single threaded or does it work from a pool of threads?
Sounds correct to me.
There are more than one event loop thread in Netty, but it does not mean a single Channel's event is handled by multiple event loop threads. Netty picks one thread and assigns it to a Channel. Once assigned, all events related with the Channel is handled by the picked thread.
It does not also necessarily mean that an event loop thread handles only one Channel. An event loop thread can handle multiple Channels.

QObject based class has a queued connection to itself

I was digging into some source code I am working on. I found a peculiar statement that someone had coded. The source code is a GUI application with a QML GUI and uses QT 4.7.x.
The snippet below belongs to core application logic.
// connect signal-slots for decoupling
QObject::connect (this, SIGNAL(setCurrentTaskSignal(int)), this,
SLOT(SetCurrentTaskSlot(int)), Qt::QueuedConnection);
It's strange that the object connects to itself via a queued connection which essentially means that the object may "live" in different threads at the same time?
At first glance It didn't made any sense to me. Can anyone think of any reason why such a connection would be plausible or needed?. Would this even work?
It will work without any problem. Maybe there was some event loop processing required before calling SetCurrentTaskSlot?
Note that QueuedConnection doesn't mean that something is in different thread. QueuedConnection means only that when signal is emitted, corresponding slot won't be called directly. It will be queued on event loop, and will be processed when control will be given back to event loop
The queued connection implies nothing about where the receiver lives. The opposite is true: to safely send signals to an object living in another thread, you must use queued connections. But you can use them for an object living in any thread!
One uses a queued connection to ensure that the signal will be delivered from within the event loop, and not immediately from the emit site as happens with direct connection. Direct connection is conceptually a set of calls to function pointers on a list. Queued connection is conceptually an event sent to a clever receiver who can execute a function call based on the contents of the event.
The event is the internal QMetaCallEvent, and it is QObject::event that acts upon this event and executes the call.

Resources