1

Having some confusion over what counts as the "Main" thread in this situation.

I have QT running in my first thread which is blocking. I want to run SDL2 in a secondary thread, with all calls and initilisation isolated to this thread.

Will this allow SDL2 to run correctly and stable as the Documentation states it needs to be in the main thread? Also this question SDL2 two windows in different threads states you can't use certain SDL2 functions outside the "main" thread.

In this case is the main thread, as far as SDL2 is concerned, the first thread containing QT, or the second thread SDL2 was initilised in?

Community
  • 1
  • 1
Scott
  • 438
  • 6
  • 18
  • 2
    This may very well be platform dependent. You are on the safe side if you instead make the first thread you created your one and only thread. In that one thread, instead of blocking with `QCoreApplication::exec()` you can call `QCoreApplication::processEvents()` in a loop together with polling SDL Events – PeterT Dec 01 '14 at 00:32

1 Answers1

0

This is just a guess, but in linux the concept of a "main thread" is the first thread in a process. Here's how to see if a thread is the main thread: Check if current thread is main thread

So to answer your question, you can't have QT running as the first thread and SDL2 running as the second. You'll either need:

  1. Two processes. Then, each is running a main thread
  2. Run SDL as the first process (the main thread) and QT as a subthread (if QT allows for this)
theicfire
  • 2,719
  • 2
  • 26
  • 29