Qt似乎使用了很多线程 [英] Qt seems to use lots of threads

查看:185
本文介绍了Qt似乎使用了很多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Qt相当多,但最近需要调试我一直在创建的线程,并发现更多的线程,然后我期待。



所以我的程序是一个简单的控制台(没有GUI)Qt应用程序(linux)。



我创建的主题:




  • 它有一个main()(它执行QtCoreApplication) - 所以这是主线程。

  • 一个线程处理从com端口接收的数据使用FTDI D2XX第三方代码驱动程序)



这就是全部。当我做ps -T ...并找到我的应用程序有7个线程。我有两个类是QObjects使用信号和槽,所以也许他们需要一个线程,每个消息处理,需要我到4个线程...所以我失去了为什么我可能有7个线程为我的应用程序。



任何人都可以详细解释发生了什么事?如果需要可以post代码。注意我只在代码中使用 new QThread 一次。

解决方案

Qt不会创建任何per - QObject 线程。它创建帮助线程,用于某些特定的原因,例如。 QProcess 有时需要辅助线程。



FTDI D2XX unix驱动程序使用libusb,实现完全向后,在你提供的线程之上的线程。坦率地说,你不应该在Linux或OS X上使用D2XX驱动程序。只需使用内核驱动程序。



你应该简单地运行D2XX驱动程序, -Qt测试应用程序打开设备并从中连续读取,并查看它产生了多少线程。你会很失望...


I have used Qt quite a lot, but recently needed to debug the threads I have been creating and found many more threads then I was expecting.

So my program is a simple console only (no GUI) Qt application (linux).

Threads that I have created:

  • It has a main() (which executes the QtCoreApplication) - so that is the main thread.
  • A thread to process received data from the com port (using FTDI D2XX thirdparty code drivers)

And that is all. When I do ps -T... and find my application there are 7 threads. I have two classes that are QObjects using signals and slots, so maybe they need a thread each for message handling, that takes me to 4 threads... so I am at a loss as to why I might have 7 threads for my application.

Can anyone explain more about what is going on? can post code if needed. Note I only use new QThread once in my code (for the moment).

解决方案

Qt doesn't create any per-QObject threads. It creates helper threads for some plaform-specific reasons, e.g. QProcess sometimes needs helper threads.

The FTDI D2XX unix driver uses libusb and that implementation is completely backwards and uses additional threads on top of the thread you've provided for it. Frankly said, you shouldn't be using the D2XX driver on Linux or OS X. Just use the kernel driver.

You should simply run the D2XX driver in a trivial non-Qt test application that opens the device and reads from it continuously and see how many threads it spawns. You'll be dismayed...

这篇关于Qt似乎使用了很多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆