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. General callback on main thread
Forum Updated to NodeBB v4.3 + New Features

General callback on main thread

Scheduled Pinned Locked Moved General and Desktop
qthreadqt5.4.2qt5.4.0
4 Posts 2 Posters 2.1k 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.
  • J Offline
    J Offline
    Jakob
    wrote on last edited by
    #1

    Some time ago I already asked this question, but there was a lot of information and I guess the real question was not really clear. By now I know better what I want:

    Post a(ny) callback on the main thread.

    Can I achieve this somehow? Something like: qApp->postEvent(GeneralCallback) where GeneralCallback could be a global function, the result of for instance std::bind.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi @Jakob,
      the ad hoc hackish way to implement such system that comes to my mind is:

      • Create an abstract base class AbstractCallback with a virtual 'callback' function
      • Create a class - that inherits AbstractCallback - for each callback function. Add member variables that store the callback arguments and a wrapper function for the actual callback function
      • Post instances of these classes to the event queue
      • Create an event filter that calls the 'callback' functions of those objects
      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jakob
        wrote on last edited by
        #3

        @Wieland Thank you for a quick response.

        I was actually thinking along the same directions. Am I correct to assume that such a approach requires me to create a custom event type using QEvent::registerEventType() for the AbstractCallback?

        Additionally, my gut feeling is that creating an event filter on the main event queue (essentially a filter on qApp I presume?) could cause quite some performance loss. Or am I too pessimistic?

        ? 1 Reply Last reply
        0
        • J Jakob

          @Wieland Thank you for a quick response.

          I was actually thinking along the same directions. Am I correct to assume that such a approach requires me to create a custom event type using QEvent::registerEventType() for the AbstractCallback?

          Additionally, my gut feeling is that creating an event filter on the main event queue (essentially a filter on qApp I presume?) could cause quite some performance loss. Or am I too pessimistic?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @Jakob said:

          Am I correct to assume that such a approach requires me to create a custom event type

          Yes.

          [...] could cause quite some performance loss. Or am I too pessimistic?

          Don't know, you'll have to meassure the impact. What I can say is that I used an event filter recently to handle input from a graphics tablet. Processing huge amounts of events in real time was no problem.

          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