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
97
votes
7 answers

Background thread with QThread in PyQt

I have a program which interfaces with a radio I am using via a gui I wrote in PyQt. Obviously one of the main functions of the radio is to transmit data, but to do this continuously, I have to loop the writes, which causes the gui to hang. Since I…
gwenger
  • 1,211
  • 3
  • 12
  • 11
73
votes
5 answers

what is the correct way to implement a QThread... (example please...)

The Qt documentation for QThread says to create a class from QThread, and to implement the run method. Below is taken from the 4.7 Qthread documentation... To create your own threads, subclass QThread and reimplement run(). For example: class…
g19fanatic
  • 10,567
  • 6
  • 33
  • 63
58
votes
3 answers

Qt signals (QueuedConnection and DirectConnection)

I'm having trouble with Qt signals. I don't understand how DirectConnection and QueuedConnection works? I'd be thankful if someone will explain when to use which of these (sample code would be appreciated).
Nika
  • 1,864
  • 3
  • 23
  • 44
42
votes
3 answers

Example of the right way to use QThread in PyQt?

I'm trying to learn how to use QThreads in a PyQt Gui application. I have stuff that runs for a while, with (usually) points where I could update a Gui, but I would like to split the main work out to its own thread (sometimes stuff gets stuck, and…
Azendale
  • 675
  • 1
  • 7
  • 17
30
votes
5 answers

Sending custom PyQt signals?

I'm practicing PyQt and (Q)threads by making a simple Twitter client. I have two Qthreads. Main/GUI thread. Twitter fetch thread - fetches data from Twitter every X minutes. So, every X minutes my Twitter thread downloads a new set of status…
Enfors
  • 960
  • 2
  • 14
  • 25
29
votes
5 answers

Qt signaling across threads, one is GUI thread?

What does it mean to move a object from one thread to another in Qt using moveToThread? Everything seems to work even before using moveToThread, which moves the object from one thread (GUI thread) to a another thread ( worked) and Qt:connect calls…
Passionate programmer
  • 5,748
  • 10
  • 39
  • 43
25
votes
8 answers

How to Compress Slot Calls When Using Queued Connection in Qt?

After reading some articles like this about Qt Signal-Slot communications I still have a question concerning the queued connection. If I have some threads sending signals all the time to each other and lets say one thread_slowis running a slow…
Michel Feinstein
  • 13,416
  • 16
  • 91
  • 173
25
votes
3 answers

QThread: Destroyed while thread is still running

I'm having problem with QThreads in python. I want to change background color of label. But My application crash while starting. "QThread: Destroyed while thread is still running" class MainWindow(QMainWindow): def __init__(self): …
Sergey Kostin
  • 359
  • 1
  • 3
  • 5
22
votes
6 answers

PyQt: How to update progress without freezing the GUI?

Questions: What is the best practice for keeping track of a thread's progress without locking the GUI ("Not Responding")? Generally, what are the best practices for threading as it applies to GUI development? Question Background: I have a PyQt…
tgray
  • 8,826
  • 5
  • 36
  • 41
22
votes
2 answers

Sending large amount of data between Qt threads

I have a QThread which generates a fairly large amount of data regularly (couple of megabytes per second), and it needs to transmit it to the parent (GUI) thread. I'm afraid I'm not that certain in the inner workings of QThread so I would like to…
vsz
  • 4,811
  • 7
  • 41
  • 78
21
votes
5 answers

How to use QThread correctly in pyqt with moveToThread()?

i read this article How To Really, Truly Use QThreads; The Full Explanation, it says instead of subclass qthread, and reimplement run(), one should use moveToThread to push a QObject onto QThread instance using moveToThread(QThread*) here is the…
Shuman
  • 3,914
  • 8
  • 42
  • 65
21
votes
3 answers

How to stop a QThread from the GUI

This is a follow up question to a previous one I posted earlier. The problem is how to stop (terminate|quit|exit) a QThread from the GUI when using the recommended method of NOT subclassing Qthread, but rather vreating a QObject and then moving it…
stefano
  • 769
  • 2
  • 10
  • 24
20
votes
2 answers

Why using QMetaObject::invokeMethod when executing method from thread

I have following code: class A : public QObject { Q_OBJECT public: A() : QObject() { moveToThread(&t); t.start(); } ~A() { t.quit(); t.wait(); } void doSomething() { …
krzych
  • 2,126
  • 7
  • 31
  • 50
19
votes
3 answers

QThread: Destroyed while thread is still running?

I would like to start my QThread when I push on button Run. But the compiler outputs following error: QThread: Destroyed while thread is still running ASSERT failure in QThread::setTerminationEnabled(): "Current thread was not started with…
The Man
  • 407
  • 1
  • 7
  • 19
18
votes
2 answers

Multithreading performance of QtConcurrent Vs QThread with many threads

Suppose your application needs to run a function in multiple threads the number of which is more than the number of CPU cores/threads. One way is to use QtConcurrent and setting the maximum thread count : MyClass *obj = new…
Nejat
  • 31,784
  • 12
  • 106
  • 138
1
2 3
99 100