gpt4 book ai didi

rename - 是否可以命名 QThread?

转载 作者:行者123 更新时间:2023-12-01 10:45:47 26 4
gpt4 key购买 nike

我有一个 Linux Qt 应用程序,它创建了一些 QThreads .

我知道当你创建一个线程时,它会继承父名,当我使用 htop 时我可以看到它。或 ps ax -L .

是否可以通过像 ps ax -L 这样的 bash 命令命名这些 QThreads 并查看它们的名称或 ‍ htop ?

最佳答案

是的,只需在启动 QThread 对象之前为其命名:

QThread* thr = new QThread(this);

thr->setObjectName("worker thread");

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.

关于rename - 是否可以命名 QThread?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26179688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com