Registering custom event types

  • Qt Champions 2017

    Is it safe to register custom event types before main()? I have the code in a .so, so I'm doing this in the header:

    class QMpiEvent : public QEvent
    	QMpiEvent(Type, QtMpi::NodeId);
    	static const Type NodeStarting;
    	static const Type NodeExiting;

    And then I register the events in the .cpp:

    const QEvent::Type QMpiEvent::NodeStarting = static_cast<QEvent::Type>(QEvent::registerEventType());
    const QEvent::Type QMpiEvent::NodeExiting = static_cast<QEvent::Type>(QEvent::registerEventType());

    Am I supposed to do the registration after the QCoreApplication has been initialized?

    Kind regards.

  • Lifetime Qt Champion


    Looking at the implementation of registerEventType, it seems you can call it before instantiating the QCoreApplication.

  • Qt Champions 2017

    Right, I peaked at it as well, but was unsure whether I might have missed something. :)

  • Lifetime Qt Champion

    Doesn't seem so :) Or we both missed it :D

  • Qt Champions 2017

    When I finish up my code the obvious run and if it crashes test will tell for sure.
    Unfortunately, the documentation is very cryptic of such issues ... :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.