custom events?
-
Hello I have an object. When an this object is constructed I would like an even to occur.
I've setup the this->installEventFilter(parent); argument in this object and I have also written a function of eventFilter(QObject *obj, QEvent *evt) to process the events.
Whats a problem for me is how do I setup a custom even so i can send it to the evenFilter() function.
Is there a good tutorial on setting up custom events?
-
@JoeJoe_000
Possibly posting this in the Jobs sub-forum is not the best place? :)Did you Google for
qt5 custom event
? A link like summarises it as just:A custom event can be handled by an object. To make a custom event you have to:
Implement this class's custom event handler (customEvent(…)), so that when an event is sent to an instance of this class, this method will be called to handle the situation.
Send an event using QApplication::postEvent(…) and give an instance of the class mentioned before as one of the parameters.BTW, did you indeed mean a
QEvent
and not just a signal to emit? -
@JonB said in custom events?:
Possibly posting this in the Jobs sub-forum is not the best place? :)
I agree, jobs is definitely the wrong sub forum.
Moved to General -
Sorry about accidentally posting in jobs section. I must have confused a few open tabs.
Yes I meant QEvent. I'll reply more on this soon...
-
@JoeJoe_000 said in custom events?:
Hello I have an object. When an this object is constructed I would like an even to occur.
Either post it manually, or do it from the object's constructor.
Is there a good tutorial on setting up custom events?
Nothing to it. Just derive
QEvent
and add appropriate methods. Register the event type withQEvent::registerEventType
on program start (or wherever appropriate). -
@JonB could you link me to the exact source you're using? Is it https://doc.qt.io/qt-5/qevent.html ?
-
@JoeJoe_000 said in custom events?:
@JonB could you link me to the exact source you're using? Is it https://doc.qt.io/qt-5/qevent.html ?
Sorry, I'm usually very good about pasting my references! I picked that one up from http://programmingexamples.wikidot.com/qt-events, right at the foot of the page. I thought that gave a nicely laid out summary.