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
11
votes
5 answers

Error "QObject::startTimer: QTimer can only be used with threads started with QThread" many times when closing application

I know this has been asked many times before. I read all of those threads, and my case seems different. Everybody else who has this trouble has a few straightforward causes that I think I’ve ruled out, such as: Starting a timer with no event loop…
Johnny J
  • 113
  • 1
  • 1
  • 4
11
votes
2 answers

QtSerialPort instantiating in wrong thread, causing signals/slots to fail

I'm using the QtSerialPort library to talk to a virtual COM port via USB. The COM port returns data and works properly when testing it with the example projects given with QtSerialPort, but fails when I run it as part of my project. I inspected the…
Mike Trpcic
  • 25,305
  • 8
  • 78
  • 114
10
votes
1 answer

PyQt5 - QThread: Destroyed while thread is still running

I am trying to figure out why this code crashes if I try to run the threads for a second time once they are completed. The first time I click "Start 5 Threads" It runs just fine and finishes. But if I click it again. The entire program crashes and I…
Zach Schulze
  • 304
  • 1
  • 4
  • 17
10
votes
1 answer

How to stop a qThread in QT

I would like to know how to properly stop a QThread. I havea infinite loop in a thread, and I would like to stop it when I do a specific action : I have tried : if (thread->isRunning()){ worker->stop(); thread->terminate(); } the stop()…
iAmoric
  • 1,787
  • 3
  • 31
  • 64
10
votes
3 answers

QThread blocking main application

I have a simple form UI that has a slot for a button, starting a thread: void MainWindow::LoadImage() { aThread->run(); } And the run() method looks like this: void CameraThread::run() { qDebug("Staring Thread"); while(1) { …
Atilla Filiz
  • 2,383
  • 8
  • 29
  • 47
10
votes
2 answers

No update in ListView

I made a class derived from QAbstractListModel and re-implemented all the necessary functions. I create an object of it, fill in some initial data into the model (all beginInsertRows etc done) and then pass it (the object) to qml via…
Vedanshu
  • 2,230
  • 23
  • 33
10
votes
3 answers

QThread emits finished() signal but isRunning() returns true and isFinished() returns false

Below is the code for my qthread implementation. I am trying to get gps data from satellite. QThread doesn't produce the finished() signal even when the programs exits gpsSearch() slot function. The function locateMe() is called whenever a button is…
Tahlil
  • 2,680
  • 6
  • 43
  • 84
10
votes
2 answers

Making the main thread wait till all other Qthread finished

is there a way to force the main thread to wait until all threads created from it, will finish their job, before finishing the program. I mean: int main(){ QthreadClass a; // in cons' a thread is created and running QthreadClass b; // same…
kakush
  • 3,334
  • 14
  • 47
  • 68
10
votes
2 answers

Simple multithreading with Qt: am I doing this right?

I'm new to StackOverflow and wondering if I'm doing this right: I'm writing a simple Qt application to test multi-threading (something I am also completely new to). I made a MainWindow that contains widgets, and a class MyThread that subclasses…
evdc
  • 185
  • 1
  • 3
  • 8
9
votes
2 answers

Wake up a QThread that is in sleep?

How can I wake up a QThread when it is sleeping? I have a thread that is running in the background and now and then wakes up and does some small stuff, however if I would like to stop that thread in a controlled manner I have to wait for him to wake…
Johan
  • 20,067
  • 28
  • 92
  • 110
9
votes
2 answers

Why does PyQt crashes without information? (exit code 0xC0000409)

I'm trying to develop a software with PyQt, but I often get stuck on software crashes without debug information (only the exit code 0xC0000409). I'm using QThread, and I wrote a system like this: class serialThreadC(QThread): updateOutBox =…
brazoayeye
  • 329
  • 1
  • 2
  • 14
9
votes
1 answer

Qt: qthread destroyed while thread is still running during closing

I have a class: class centralDataPool : public QObject { Q_OBJECT public: centralDataPool(QObject * parent = 0); ~centralDataPool(); commMonitor commOverWatch; private: QThread monitorThread; int totalNum; signals: void…
Nyaruko
  • 4,329
  • 9
  • 54
  • 105
9
votes
3 answers

how can i inherit from both QWidget and QThread?

I have a class like this class GUI : public QWidget, public QThread When I do the above i get errors about connect signals. The error says Reference to "connect" is ambiguous. Is there a way to inherit from both? Thank you
infinitloop
  • 2,863
  • 7
  • 38
  • 55
9
votes
1 answer

Proper use of QThread.currentThreadId()

I thought that determining ID for the QThread currently running a function was QThread.currentThreadId(). However I find this does not give the expected results (in PyQt5 with python 3; but I have no reason to believe it would be different with…
Oliver
  • 27,510
  • 9
  • 72
  • 103
9
votes
1 answer

Qt Main-Gui and other thread + events loops

I'm trying to understand the whole internal process of Qt and how it works when I'm working with different threads. As I've understood (googling and exploring the Qt source code), is as following: Each thread has a local "pending event list" and a…
ABu
  • 10,423
  • 6
  • 52
  • 103