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
18
votes
3 answers

PyQt: Connecting a signal to a slot to start a background operation

I have the following code that performs a background operation (scan_value) while updating a progress bar in the ui (progress). scan_value iterates over some value in obj, emitting a signal (value_changed) each time that the value is changed. For…
Hernan
  • 5,811
  • 10
  • 51
  • 86
18
votes
5 answers

How can I terminate a QThread

Recently ,I come across this problem as I memtioned in this Title. I have tried by using QThread::terminate(),but I just can NOT stop the thread ,which is in a dead loop (let's say,while(1)). thanks a lot.
user230938
  • 191
  • 1
  • 1
  • 4
18
votes
3 answers

C++/Qt - QThread vs QRunnable

What are the differences between QThreads and QRunnable ? When should I use QThread and when QRunnable ?
CDT
  • 10,165
  • 18
  • 66
  • 97
17
votes
6 answers

Starting QTimer In A QThread

I am trying to start a QTimer in a specific thread. However, the timer does not seem to execute and nothing is printing out. Is it something to do with the timer, the slot or the thread? main.cpp #include "MyThread.h" #include
Tudor Pascu
  • 183
  • 1
  • 2
  • 6
16
votes
3 answers

QThread vs std::thread

I saw different topics on "pthread vs std::thread" and "QThread vs pthread" but none on "std::thread vs QThread". I have to program a software to drive a 3D Printer and need to use threads. There will be a thread that will check safety constantly,…
ElevenJune
  • 423
  • 1
  • 4
  • 21
16
votes
1 answer

QObject::connect: Cannot queue arguments of type 'int&'

I tried to do this : connect(this, SIGNAL(signalClicked(int&)), classA, SLOT(doWork(int&))); But I get the message in the title. So I've explored the internet and I came up with this solution which is not working either: …
Thibel
  • 277
  • 1
  • 5
  • 13
16
votes
2 answers

PySide/PyQt - Starting a CPU intensive thread hangs the whole application

I'm trying to do a fairly common thing in my PySide GUI application: I want to delegate some CPU-Intensive task to a background thread so that my GUI stays responsive and could even display a progress indicator as the computation goes. Here is what…
user1491306
  • 163
  • 1
  • 6
15
votes
2 answers

Qt: Correct way to post events to a QThread?

In my Qt application, I have a main thread and a worker thread. The worker thread subclasses QThread and processes events via customEvent. Is this the correct way for the main thread to send events to be processed by the worker thread? QThread*…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
15
votes
3 answers

Qt timers cannot be stopped from another thread

Hy, I'm writing my first Qt program and getting now in troubles with: QObject::killTimer: timers cannot be stopped from another thread QObject::startTimer: timers cannot be started from another thread My program will communicate to a CANOpen bus for…
Matt
  • 169
  • 1
  • 1
  • 7
14
votes
3 answers

QT threads :Getting QObject::startTimer: timers cannot be started from another thread warning

I follow the examples from the Qt SDK, starting timer in the QThread Subclass but I keep getting the warning and the thread never starts the timer. Here is the code: NotificationThread::NotificationThread(QObject *parent) …
user63898
  • 29,839
  • 85
  • 272
  • 514
13
votes
3 answers

How to queue lambda function into Qt's event loop?

Basically I need the same thing that is done like this in Java: SwingUtilities.invokeLater(()->{/* function */}); Or like this in javascript: setTimeout(()=>{/* function */}, 0); But with Qt and lambda. So some pseudocode: Qt::queuePushMagic([]()…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
12
votes
5 answers

How to plot on my GUI

I'm designing a GUI with PyQt where I need to display a matplotlib/pylab window when I click on a button that makes the plot of the data from a function I've created. It's like a runtime used in Matlab. I want to keep the matplotlib/pylab window as…
Ricardo Alberto
  • 121
  • 1
  • 1
  • 4
12
votes
4 answers

g_main_loop_run blocks the Qthread and does not allow to stop video

I have created a separate class for gstreamer to stream videos. This class runs on separate thread by using moveToThread(). I am using Qt5.5 for development. When I issue startcommand on main thread , Qthread starts and gstreamer uses…
samprat
  • 2,150
  • 8
  • 39
  • 73
12
votes
1 answer

Set priority to GUI thread in Qt

Is it possible to set priority to the main GUI thread so it has higher priority comparing to the other threads (QThread)? My aim is to not to freeze up the GUI while the other threads are doing some intensive computation which may occupy CPU to 100%…
John Yang
  • 547
  • 1
  • 8
  • 21
11
votes
1 answer

How to send a Qt signal containing a cv::Mat?

In short, I get following error: QObject::connect: Cannot queue arguments of type 'cv::Mat' (Make sure 'cv::Mat' is registered using qRegisterMetaType().) What I'm trying to do is send a signal containing two cv::Mat images from a QThread to the…
Raf Berkvens
  • 167
  • 1
  • 8