Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to name a QThread?

I have a Linux Qt application that creates some QThreads.

I know that when you create a thread it inherits the parent name and I can see it when I use htop or ps ax -L.

Is it possible to name those QThreads and see their names via a bash command like ps ax -L or ‍htop?

like image 775
Gappa Avatar asked Mar 18 '23 07:03

Gappa


1 Answers

Yes just give the name to the QThread object before starting it:

QThread* thr = new QThread(this);

thr->setObjectName("worker thread");

in the docs:

To choose the name that your thread will be given (as identified by the command ps -L on Linux, for example), you can call setObjectName() before starting the thread. If you don't call setObjectName(), the name given to your thread will be the class name of the runtime type of your thread object (for example, "RenderThread" in the case of the Mandelbrot Example, as that is the name of the QThread subclass). Note that this is currently not available with release builds on Windows.

like image 51
ratchet freak Avatar answered Apr 07 '23 04:04

ratchet freak