Is it possible in Qt to track if a new QWindow has been added via SIGNAL? It is necessary that a particular object to monitor the appearance of these windows.
- 2What kind of windows? How are they added? - ixSci
- It is necessary to track the addition of a new QWindow. Now I check it with a thread using QApplication :: allWindows (). Therefore, I wonder if there is a method using SIGNAL to organize it. - Galitsky Oleg
|
1 answer
There is no ready signal. But you can handle messages about the creation of widgets. To do this, you need to define a message filter and connect it to the QApplication application object.
Here is an example:
class WindowsMon: public QObject { Q_OBJECT; public: using QObject::QObject; private: bool eventFilter(QObject * target, QEvent * e) override; public: signals: void windowCreated(QWindow * w); }; bool WindowsMon::eventFilter(QObject * target, QEvent * e) { if(e && QEvent::Create == e->type()) { const auto window = qobject_cast<QWindow *>(target); if(window) // смогли пребразовать к QWindow { emit windowCreated(window); } } // на самом деле мы ничего не фильтруем, поэтому пробрасываем // сообщения дальше, тем более что висим на QApplication return QObject::eventFilter(target, e); } Connection:
auto winmon = new WindowsMon(QCoreApplication::instance()); QCoreApplication::instance()->installEventFilter(winmon); - Your option helped, but only instead of QApplication I had to register QCoreApplication. I'm still new to qt and scorched at random, but lucky. Thanks again! - Galitsky Oleg
- @ GalitskyOleg I see you are new, so I’ll tell you: comments here for discussion if something is not clear. But these "hello", "thank you", "pozhalusta" though pleasant, but not quite welcome as it creates an extra noise. It is understood that these words are. - Cerbo pm
|