Re: How to send custom events from QThread:: run () to application.
Hello.
I have a need to send a custom event from a thread into the application, but I have nothing.
I do so:
1. My custom event:
Code:
class CustomEvent
: public QEvent{
public:
CustomEvent ()
...
...
}
2. My implementation of a class QThread:
Code:
void MyThread::run()
{
while (!stopped) {
//Processing.
...
...
//For some conditions, generates an event.
CustomEvent *e = new CustomEvent ();
//Processing.
...
...
}
}
3. My main (and only) widget application:
Code:
void TestWidget
::customEvent(QEvent *e
) {
if (e
->type
() == (QEvent::User + 1)) {
qDebug() << "TestWidget::customEvent() caught";
}
}
But I have a message "caught" is displayed. What am I doing wrong?
PS: I tried to override the same method "eventFilter()", as well as install "installEventFilter(qApp)" but nothing happens. Help please.
Added after 21 minutes:
Oops, sorry problem solved.
Instead
Code:
myWidget->installEventFilter(qApp)
need
Code:
qApp->installEventFilter(myWidget)
:)