4

I use qt a lot. I want to know something: how many threads does Qt create do to things in the background? like handling signals and slots..

Also, any GUI toolkit creates Event threads too (i seem to remember java does). Does Qt create one too?

EDIT: when I say "how many threads", I really mean which threads

Thanks,
jrh

jrharshath
  • 25,975
  • 33
  • 97
  • 127

3 Answers3

8

Qt's signals and slots are not implemented using multiple threads, they're just a way of handling the bookkeeping for event distribution.

One thing you can do is run your program, count the threads using whatever OS facility you like (such as Task Manager on Windows), and see whether that matches what you expect. I wouldn't expect Qt to create any additional threads unless you ask it to.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3

As Greg mentioned, signals and slots do not use threads. Generally, Qt will never create threads to do things in the background, Except:

  • The Network code, which can create a thread to do DNS lookups.

  • The QThreadPool will create N + 1 threads when you initialise it (or use it for the first time), where N is the number of CPU cores.

Cheers,

Thomi
  • 11,647
  • 13
  • 72
  • 110
3

QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TimW
  • 8,351
  • 1
  • 29
  • 33