Out of habit, with WinApi you need to find a substitute for SendMessage, PostMessage in Qt, so that some operations less meaningful and more demanding to defer for a period of message processing, but not during the execution of the interrupt handler, or any triggers.

In Qt your custom types are described by a separate event class that is based on QEvent

1
2
3
4
5
6
7
8
9
10
11
12
class MyEvent
: public QEvent
{
public:
MyEvent()
: QEvent( (QEvent::Type)(QEvent::User + 1) )
{}

private:

// --
};

Processing of messages by overriding the “event” method in the widget

boolevent(QEvent *event);

Here is a sample code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define MY_EVENT_TYPE (QEvent::User + 1)

bool myWidget::event(QEvent *event)

{

if (event->type() == MY_EVENT_TYPE) {

MyEvent *myEvent = static_cast(event);

// custom event handling here

// do something...

return true;

}

return QWidget::event(event);

}

Sending these messages via the method of application class by post or send method depending on your situation

1
mApp->postEvent( this, new MyEvent() );

where mApp – pointer to the application class

In this case, after processing the memory of events will be automatically released.

Qt and messages queue
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *