Registering custom event types


  • Qt Champions 2016

    Hello,
    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
    {
    	Q_GADGET
    
    public:
    	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

    Hi,

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


  • Qt Champions 2016

    @SGaist
    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 2016

    @SGaist
    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.