简体   繁体   English

Qt中的win32线程

[英]win32 threads in Qt

Is there a way to create a thread in Qt without using subclassing (ie. making a QThread class)? 有没有一种方法可以在Qt中创建线程而不使用子类化(即创建QThread类)? It's getting difficult sending data into the thread. 将数据发送到线程中变得越来越困难。 Is is possible to use win32 threads in Qt if so can someone give me an example on how to? 如果有人可以给我一个例子,可以在Qt中使用win32线程吗?

Thanks. 谢谢。

您不一定必须继承QThread的类-参见此处的讨论http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

Or if you have many simple tasks and want to have them processed in threaded fashion. 或者,如果您有许多简单任务,并且希望以线程方式处理它们。 QRunnable and QThreadPool provide a quick and easy approach without dealing with threads themselves. QRunnableQThreadPool提供了一种快速简便的方法,而无需自己处理线程。

If you just want to run a function in another thread you should check the QT Concurrent Namespace. 如果只想在另一个线程中运行函数,则应检查QT并发命名空间。

The following example will run the function 'aFunction()' in separate thread and will not block on the line where calling the function. 以下示例将在单独的线程中运行函数'aFunction()',并且不会在调用该函数的行上阻塞。 Of course there are mechanisms to understand when a function ends, to get a result, to wait for it. 当然,有一些机制可以理解函数何时结束,获取结果,等待结果。

void aFunction(int arg1, double arg2, const QString &string);

int integer = ...;
double floatingPoint = ...;
QString string = ...;

QtConcurrent::run(aFunction, integer, floatingPoint, string);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM