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

Accessing Object members in another QThread

I have 2 Threads in a Qt5Application: Thread A: contains a bunch of QObject derived class objects Thread B: worker in this Thread has all the pointers to the objects in A Thread A might be very busy at times and Thread B is only there to delegate…
Mindcode
  • 71
  • 1
  • 2
7
votes
1 answer

How to check if an event loop has pending events outside of a thread?

Calling QCoreApplication::hasPendingEvents() or QAbstractEventDispatcher::instance()->hasPendingEvents() inside of a thread works just fine. However, outside of it, the latter one (with appropriate parameter) always returns false (former cannot be…
AlexP
  • 1,416
  • 1
  • 19
  • 26
7
votes
5 answers

Speeding up writing images into hard disk in OpenCV

I am working with a 50 fps camera (in Ubuntu environment and Qt framework) and every 20 ms I get a frame to process. I wrote a code to read images from camera and then store them in hard drive. while(3.14) { cv::Mat Camera_Image = Capture_Image(); …
PsP
  • 696
  • 3
  • 10
  • 34
7
votes
2 answers

QApplication thread freezes because of another QThread

In my Qt application I create a QThread that should perform some heavy calculation task regularly. Main QApplication thread is supposed to maintain a GUI (not included in example) and perform some regular updates as well. Both threads have their own…
7
votes
1 answer

How to signal from a running QThread back to the PyQt Gui that started it?

I am trying to understand how to use signaling from a Qthread back to the Gui interface that started. Setup: I have a process (a simulation) that needs to run almost indefinitely (or at least for very long stretches of time)., While it runs, it…
stefano
  • 769
  • 2
  • 10
  • 24
6
votes
2 answers

Pause and Resume a QThread

I've recently began learning about QThreads and I've a program which runs a 4 hours long loop in a separate thread (so that I may continue to use the GUI). What I am after is, something that will pause/suspend the thread when the user clicks pause…
Jean-Luc
  • 3,563
  • 8
  • 40
  • 78
6
votes
2 answers

PyQt4 Results in QThread error

Using PyQt4 4.8.6 the code below produces the error QObject::startTimer: QTimer can only be used with threads started with QThread when a is used as the variable for QApplication, but it does not produce the error if cpp (or most anything else) is…
MES
  • 223
  • 2
  • 6
6
votes
1 answer

Looping QProgressBar gives error >> QObject::installEventFilter: Cannot filter events for objects in a different thread

This question seems to have been asked many times in many different forms but I haven't managed to find one with a -relevant to my code- solution. When I run the program it shows QObject::installEventFilter: Cannot filter events for objects in a…
Jay
  • 3,373
  • 6
  • 38
  • 55
6
votes
5 answers

How to use QTimer to print a message to a QTextBrowser every 10 seconds?

I have working at this for hours and cannot figure it out nor can I find any help online that works. Basically the gist of what I am trying to accomplish is to have a Qt GUI with a button and a QTextBrowser. When I push the button I want it to…
Aaron McKellar
  • 627
  • 4
  • 10
  • 20
6
votes
1 answer

Restart QThread with GUI

I am using QThread to do some calculations in a separate Thread. The Thread gets started by a button click, witch launches the function StartMeasurement(). The Thread can finish the process by itself (after finished the calculations) and emits the…
MartinaW
  • 197
  • 1
  • 4
  • 7
6
votes
1 answer

Qt, How to pause QThread immediately

I have an QThread which listen server. I want to pause work of QThread immediately. Not waiting at all, but almost like terminating, it must be immediate.
DJ.Yosemite
  • 285
  • 4
  • 13
6
votes
1 answer

Passing parameter to a pyqt thread when started

Is there any way we can pass a parameter to QThread when the thread is started (.start) ? I found an example of using pyqt thread in stackoverflow, but I was wondering how to pass a parameter, in case I want the worker thread to process a data that…
electro
  • 911
  • 4
  • 12
  • 28
6
votes
2 answers

QSignalSpy can not be used with threads

I wrote a thread that executes a worker object. Everything works fine. Also the resulting signals are emitted as they should. Of course I took care of the usual mistakes regarding thread/object affinity. Today I wrote an automated module test for…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
6
votes
2 answers

How to release memory of Qthread object?

I have done something like this: //in the mainwindow's constructor QThread *thr = new QThread; soundWorker * work = new soundWorker; connect(this,SIGNAL(playsound()),work,SLOT(process())); work->moveToThread(thr); thr->start(); Shall I delete thr…
Nyaruko
  • 4,329
  • 9
  • 54
  • 105
6
votes
2 answers

How to safely destruct a QThread?

I want to properly destruct a QThread in Qt 5.3. So far I have got: MyClass::MyClass(QObject *parent) : QObject(parent) { mThread = new QThread(this); QObject::connect(mThread, SIGNAL(finished()), mThread, SLOT(deleteLater())); mWorker =…
Niklas
  • 23,674
  • 33
  • 131
  • 170