Questions tagged [qthread]

QThread is a threading class provided by the cross-platform Qt framework.

As of Qt 4.3, the default QThread object executes an event loop in his run() method. Thus, it is discouraged to subclass QThread for concurrent execution. Instead all operations which are required to be executed concurrently should be encapsulated into one or more QObject with signals and slots as a mechanism to communicate data. These objects can then be "moved" to the Qthread object.

This allow concurrent programming without the need for a lock, a condition variable, or a semaphore

Helpful links:

Frequently Asked Questions About QThread:

1528 questions
9
votes
2 answers

QThread finished() connected to deletelater of a QObject

I have thought a lot and read lot of articles before asking this question here. None of the articles gave me a proper answer. http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ QThread* thread = new…
Srikan
  • 2,161
  • 5
  • 21
  • 36
8
votes
1 answer

QThread in Qt on Python

I employed QThread using a worker object after reading extended discussions on how QThread should be used and overwriting its run method via subclassing it is not the proper method. However, in the method I intend to use I need to pass an additional…
Vesnog
  • 773
  • 2
  • 16
  • 33
8
votes
2 answers

Pyinstaller doesn't work properly with threading

A program that runs a bat file which contains instruction for running an executable(longTask) using Qthread but it doesn't work as expected when I create an executable using Pyinstaller with the following command. I gave '--windowed' to do not…
Nagamani
  • 165
  • 1
  • 12
8
votes
1 answer

Move QTcpSocket to a new Thread after the connection is initiated

I've got a threaded server. QTcpSocket needs to be created on the thread it needs to be ran on, FI: Qt - Handle QTcpSocket in a new thread by passing the socket descriptor. My problem is that, I need to have a pool of thread and move the socket on a…
Damien
  • 1,492
  • 10
  • 32
8
votes
4 answers

QObject::startTimer: Timers can only be used with threads started with QThread

I am trying to start a Timer in a worker thread's event loop, but I get this error: QObject::startTimer: Timers can only be used with threads started with QThread Whats wrong with this? #include #include #include class…
user2950911
  • 873
  • 3
  • 12
  • 19
8
votes
2 answers

Threaded OpenGL with shared QGLWidgets issue with Qt 5.1

I use two QGLWidgets. One for loading textures and one for rendering, but it is not working. I used the following explanation from http://blog.qt.digia.com/blog/2011/06/03/threaded-opengl-in-4-8/ Texture uploading thread Uploading many (or…
riv333
  • 389
  • 2
  • 12
8
votes
3 answers

How to set the name of a QThread in pyqt?

I am using QtCore.QThread (from PyQt4). To log, I am also using the following formatter : logging.Formatter('%(levelname)-8s %(asctime)s %(threadName)-15s %(message)s') The resulting log is : DEBUG 2012-10-01 03:59:31,479 Dummy-3…
Xavier V.
  • 6,068
  • 6
  • 30
  • 35
8
votes
4 answers

QThreads , QObject and sleep function

The problem I encountered is that I decided to implement QThreads the way they are supposed to, based on numerous…
Erich Jagomägis
  • 285
  • 1
  • 4
  • 13
7
votes
3 answers

CPU Cores not Utilized properly using QThreads

Using : C++ (MinGW), Qt4.7.4, Vista (OS), intel core2vPro I need to process 2 huge files in exactly the same way. So i would like to call the processing routine from 2 separate threads for 2 separate files. The GUI thread does nothing heavy; just…
ustulation
  • 3,600
  • 25
  • 50
7
votes
3 answers

How to implement a QThread that runs forever{} with a QWaitCondition but still needs to catch another Slot while doing that

I implemented a class that can write data to a serial port via a QQueue and read from it by a slot. I use QAsyncSerial for this which in turn uses boost::asio with a callback. The class is moved to a thread and its start() method is executed when…
Strayer
  • 3,050
  • 3
  • 30
  • 40
7
votes
2 answers

Qt moveToThread() vs calling new thread when do we use each

When do we use each of this function calls in a threaded application. given two functions fun1() and fun2() defined in the same class dealing with read/write of data into buffers(queue operation). to achieve multi-threading to these. we would have…
Aditya P
  • 1,862
  • 5
  • 28
  • 39
7
votes
3 answers

How to prevent the QBasicTimer::stop: Failed warning when objects become threadless?

QObjects can easily become threadless, when their work thread finishes ahead of them. When this happens, Qt doesn't release their timer ids, even though the timers are not active anymore. Thus, a QBasicTimer::stop: Failed. Possibly trying to stop…
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
7
votes
1 answer

PyQt5: Timer in a thread

Problem Description I'm trying to make an application that collects data, processes it, displays it, and some actuation (open/close valves, etc). As a practice for future applications where I have some stricter time constraints, I want to run the…
robotHamster
  • 609
  • 1
  • 7
  • 24
7
votes
1 answer

PyQt: QThreadPool with QRunnables taking time to quit

I've a class who create QRunnables and start them in a QThreadPool instance. My threads are working well, but in case user want to quit application, the application takes a long time to stop. Certainly due to the fact that the requests launched take…
Algorys
  • 1,710
  • 2
  • 25
  • 52
7
votes
1 answer

How to leverage Qt to make a QObject method thread-safe?

Suppose we wrote a non-const method in a QObject-deriving class: class MyClass : public QObject { int x; public: void method(int a) { x = a; // and possibly other things }; }; We want to make that method thread-safe: meaning that calling…
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313