Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Registering custom event types
Forum Updated to NodeBB v4.3 + New Features

Registering custom event types

Scheduled Pinned Locked Moved Solved General and Desktop
eventevent loop
5 Posts 2 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #1

    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.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      kshegunovK 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

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

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          kshegunovK 1 Reply Last reply
          0
          • SGaistS SGaist

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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @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 ... :)

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved