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
6
votes
1 answer

How to setup QSerialPort on a separate thread?

Following the official documentation I'm trying to do this: MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QThread *thread = new QThread; Worker *worker= new Worker(); worker->moveToThread(thread); //init…
anat0lius
  • 2,145
  • 6
  • 33
  • 60
6
votes
3 answers

calling QThread.exec() method is necessary in QThread?

I am not calling exec() in my code, but the timer and QUdpSocket is working fine. Is exec() used to wait for an event to continue? UPDATE: the timer was working, because I had not called moveToThread(this) on the QThread, which meant the QThread…
yan bellavance
  • 4,710
  • 20
  • 62
  • 93
6
votes
3 answers

QThread::wait() does not return without using direct connection

I got some trouble with Qt Threads and Connections. I found several tutorials and discussions on this topic, I followed this tutorial to create the thread. But I still got the problem, that calling wait() on the thread never returns and the UI…
Kanalpiroge
  • 516
  • 4
  • 9
6
votes
2 answers

What happens to QThread when application is being closed without proper wait() call?

In the example below (inside Qt GUI application) a new thread is started (with an event loop in which I want some work to be done): void doWork() { QThread* workerThread = new QThread(); Worker* worker = new Worker(); …
sthlm58
  • 1,142
  • 1
  • 9
  • 28
6
votes
3 answers

Using QThread and moveToThread properly with QTimer and QTcpSocket

From reading this blog, this blog and some others, Subclassing QThread is bad practice. So I tried to apply this method. But my problem is that I have a QTimer and a QTcpSocket in the class I want to move to a different thread. Suddenly, it's not as…
dyesdyes
  • 1,147
  • 3
  • 24
  • 39
6
votes
1 answer

PyQt - running a loop inside GUI

I've got a Python code with some while loop inside, but I don't know how to make it work with my PyQt GUI - I can only run the Qt window or that loop (but then windows doesn't show). Is there any solution to this? I read about some QThreads or…
bartekmp
  • 403
  • 3
  • 9
  • 21
6
votes
2 answers

Correct way of threading in Qt

I have time consuming image loading (image is big), also some operations on it are done when loading. I do not want to block application GUI. My idea is to load image in another thread, emit signal that image is loaded and then redraw view with…
krzych
  • 2,126
  • 7
  • 31
  • 50
6
votes
2 answers

QReadWriteLock recursion

I'm using QReadWriteLock in recursive mode. This code doesn't by itself make sense, but the issues I have arise from here: lock->lockForWrite(); lock->lockForRead(); lockForRead is blocked. Note that this is in recursive mode. The way i see it is…
0xbaadf00d
  • 2,535
  • 2
  • 24
  • 46
6
votes
5 answers

Invoking methods in QThread's context

In my application there's the main thread and a worker thread (QThread). From the main thread I'd like to invoke a method of my worker thread and have it run in the thread's context. I've tried using QMetaObject::invokeMethod and give it the…
Idan K
  • 20,443
  • 10
  • 63
  • 83
5
votes
2 answers

Running a function in different thread in QT

In Qt Application code Class A has one member method like method1(). I want to call this method in another member function method2() and run mehtod1() in a different thread. But what I found from the qt documentation is follows. Inherit a new class…
Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
5
votes
1 answer

How to use a Qthread to update a Matplotlib figure with PyQt?

I'm really having a hard time to understand how to use Threads in PyQt. I made a simple example of what I would like to do in my UI. In the code you can see below, I want the user to enter a stock ticker (you can enter "bby", "goog" or "v" for…
BillyBoom
  • 191
  • 2
  • 14
5
votes
2 answers

Stop Qt Thread : calling exit() or quit() does not stop the thread execution

Created a QThread in main() i.e Main thread. Moved a worker class to the new thread. The thread executes the 'StartThread' method of worker class. Worker Thread: //header file class Worker : public QObject { Q_OBJECT public: Worker(QThread*…
Mandar
  • 91
  • 2
  • 6
5
votes
1 answer

PySide passing signals from QThread to a slot in another QThread

I solved my issue by moving the mySubQThread run() into the myQThread run() That said, I still would like to know why what I was attempting before didn't work. I'm pretty new to threading. I am running into this issue and I think I may be…
Tom Myddeltyn
  • 1,307
  • 1
  • 13
  • 27
5
votes
2 answers

Pause & Resume QThread

I'm trying to Pause a QThread and resume it. So, i have an RFID Reading Loop in the QThread and i want to pause the endless loop when the reader gets an RFID Code. After that, there is a db checking. At the end of the check, i want to resume the…
5
votes
1 answer

Multithreaded Qt Application does not stop when quit

I'm writing a simple Qt program to capture video feed from camera (using OpenCV). I'm using a QThread object that loops, capturing images and feeding them to the MainWindow object. This is working as it should. The problem is that when I close, the…
birgersp
  • 3,909
  • 8
  • 39
  • 79