D
D
Dima Bck2021-11-24 18:00:16
Qt
Dima Bck, 2021-11-24 18:00:16

Why doesn't QGuiApplication emit a signal?

There is a code:

#include <qapplication.h>
#include <qguiapplication.h>
#include <qscreen.h>
#include <qlist.h>
#include <qdebug.h>

int main(int argc, char* argv[])
{
    QApplication a(argc, argv);

    for (;;) {
        auto countMonitor = QGuiApplication::screens();
        qDebug() << countMonitor.size();
    }

    return a.exec();
}

I connect 2 monitors, run the program, 2 is displayed, if I turn off 1 of the monitors (at runtime), 2 will be displayed as it was. If I run the program with 1 monitor turned on, 1 is displayed, if I connect the 2nd monitor (at runtime), 1 will be displayed as it was. Why is that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2021-11-25
@provokator2020

I checked it on my computer. Windows 10, Qt 5.15.2. Indeed, when the monitor is connected/disconnected, the signals are not called. After a cursory review of the Qt sources, I came to the conclusion that this functionality is not implemented for Windows.

F
Flysink, 2021-11-24
@Flysink

In the system, when a new monitor is added, a signal is sent, since you are counting the number of monitors in an infinite loop, the main event loop cannot go through the events until you exit your loop.
Try adding:
QGuiApplication::processEvents();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question