Questions tagged [qmutex]

The QMutex class, part of the Qt framework, provides access serialization between threads.

The purpose of a QMutex is to protect an object, data structure or section of code so that only one thread can access it at a time (this is similar to the Java synchronized keyword). It is usually best to use a mutex with a QMutexLocker

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

42 questions
0
votes
0 answers

QThread, two QTimer's and QMutex deadlock

I have QObject with method, protected with QMutex. This method can be directly run from many threads. And I have another QObject living in other QThread with two QTimers. Timers have different intervals and on timeout() call method of first…
0
votes
1 answer

QMutex::lock() taken by same QThread several times consecutively

I have a QThread spawned off from my main that is doing a synchronous read on a device. The read has a 1000ms timeout. The read is wrapped in a forever loop, and the read is protected with a QMutex. The basic code is: Thread 1 - Read forever on a…
Matt Brown
  • 435
  • 4
  • 17
0
votes
0 answers

QMutex locked by unknown thread

In the following code, I get an ASSERT in unlock (), because lockingThreads (a QList) does not contain the unlocking (current) thread. Examining lockingThreads, I find an "ntdll" thread that I have no idea what it does and only disassembly…
charlie
  • 68
  • 2
  • 8
0
votes
1 answer

How to fix "In Qt two timer to one function, use qmutex will qeventloop for sleep"

I have some code use qtcpsocket to write and read, write-->sleep-->read; and ui had 2 and more timer to use this function; by i want i run synchronous;so i add mutex to lock it; by it deadlock; qt4; qt5; void MainWindow::Start() { pTimer =…
danny
  • 9
  • 2
0
votes
1 answer

QTimer timeout and QMutex interaction

Let's say we have some basic timer and a slot which is invoked periodically. SomeObject::SomeObject() { QTimer *timer = new QTimer; connect(timer , SIGNAL(timeout()), this, SLOT(updateState())); } void SomeObject::updateState() { // some…
Shf
  • 3,463
  • 2
  • 26
  • 42
0
votes
1 answer

Check which thread has locked a QMutex

I am facing a weird deadlock when doing something in our database program. The critical point is when thread tries to lock a QMutex: QMutexLocker locker(&tableMutex_); That makes the program go stuck. I'm baffled, because no other thread - AFAIK -…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
0
votes
1 answer

child GUI doesn't showup when waitcondition is used in parent pyqt

I am new to PyQt coding. I am trying to launch a child process (GUI) from parent. In this I am using waitcondition and mutex to understand its functionality.Here is my code: import sys from PyQt4 import QtGui, QtCore waitCondition =…
SKP
  • 33
  • 6
0
votes
1 answer

QMutex with QConcurrent::run not working as expected?

I am making a Qt GUI application that uses a custom QLabel class (name as ImageInteraction) to show images from a streaming camera while also allowing mouse interaction on the image. As the GUI has other functionalities, the customized QLabel class…
the_naive
  • 2,936
  • 6
  • 39
  • 68
0
votes
1 answer

should the mutexlocker be both added into two functions where they tried to visit and write the same variable from different thread?

Here is a global variable: extern int i; Two threads A & B try to visit and write the variable i, the function in thread A just as beneath: void funA(int *i) { QMutexLocker(&m_mutex); //to lock the process *i += 5; } and thread B process…
wolfguolei
  • 23
  • 3
0
votes
2 answers

Waiting for the first unlocked QMutex if there are few QMutex

I have two QMutex objects and I need to lock them both, erase() method. But the sequence is not important. So, now I am waiting while one QMutex is in unlocked (QMutexLocker locker(&listMutex)) state and than I wait for another (QMutexLocker…
Funt
  • 399
  • 8
  • 23
0
votes
3 answers

QThread state when at start() call thread is still running, but after is already not

I have a GUI thread where I call write(QString text) method of another MyQThread. MyQthread contains QMutex mutex and QList list. Here is the write() and run() methods of MyQThread: void MyQThread::write(QString text) { …
Funt
  • 399
  • 8
  • 23
0
votes
0 answers

Why is QMutex used in this code?

I was reading someone else's code and I encountered this piece of code that is part of a multi - threaded application .This code is part of the run() function in a class which is inherited from QThread. I thought QMutex is used for protecting a…
s4eed
  • 7,173
  • 9
  • 67
  • 104
1 2
3