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

Qt: Best practice for a single instance app protection

QSingleApplication? QMutex? QSharedMemory? I'm looking for something that will work smoothly in Windows, OSX and Linux (Ubuntu). Using Qt 4.7.1
JasonGenX
  • 4,952
  • 27
  • 106
  • 198
19
votes
3 answers

How to use QMutex?

I'm newbie to Qt and I'm looking for multi-threading in Qt. As I learned in Qt Documents, I defined two class for two thread: #include #include class thread_a : public QThread { Q_OBJECT public: explicit thread_a(QObject…
S.M.Mousavi
  • 5,013
  • 7
  • 44
  • 59
14
votes
1 answer

Can mutex-locking function be marked as const

I have thread-safe Document class representing custom document. It have getters (const functions) and setters to modify it's state. All these functions are mutex-protected to guarantee document will not changed until the method will be completely…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
6
votes
1 answer

Multipass totally broken on MacOS & multipassd error logs

The com.canonical.multipassd service is constantly logging errors on my Mac and multipass won't work at all, even after reinstalling, rebooting, and updating my Mac. In an attempt to use my GPU in a Linux VM through multipass, I tried to install the…
NJenkins
  • 151
  • 1
  • 5
5
votes
5 answers

Does QMutex need to be static so other threads calls of this class instance know to suspend their operations?

From multiple threads the following append function is called. I don't want data to re-write an append because the counter had not yet been incremented. Will this suspend all threads coming in except for the one currently using Append? Or will…
jdl
  • 6,151
  • 19
  • 83
  • 132
4
votes
2 answers

Pixmap shared between threads in Qt

I've got a main GUI class and another Worker class: the first copes with GUI things (drawing a QPixmap into a QGraphicsScene), the second with computations thing (drawing QLines and QPoints onto that QPixmap). The two classes run in two different…
Michael
  • 876
  • 9
  • 29
3
votes
2 answers

In Qt, how do I query the state of a QMutex or a QReadWriteLock?

I'm using a QReadWriteLock in my application to guard access to a resource object. I'm using QReadLocks and QWriteLocks where I can, but sometimes I need a "long-lived" lock that crosses function boundaries. So sometimes I need to be able to query…
Lucas
  • 6,328
  • 8
  • 37
  • 49
3
votes
4 answers

QMutex stuck in locked state

I have a function which is part of a class and in this function there is a mutex.lock at the beginning of the function and a mutex.unlock just before its return. Now I have encountered a situation where the mutex is stuck in the locked state. What…
yan bellavance
  • 4,710
  • 20
  • 62
  • 93
2
votes
1 answer

How to use QMutex correctly with QThread?

from PyQt5.QtCore import * from PyQt5.QtWidgets import * import time import sys import numpy as np class Mainthread(QThread): def __init__(self, parent): super().__init__(parent) self.parent = parent …
kerz
  • 67
  • 6
2
votes
1 answer

And odd use of conditional variable with local mutex

Poring through legacy code of old and large project, I had found that there was used some odd method of creating thread-safe queue, something like this: template < typename _Msg> class WaitQue: public QWaitCondition { public: typedef _Msg …
Swift - Friday Pie
  • 12,777
  • 2
  • 19
  • 42
2
votes
1 answer

Is threading.Lock() compatible with QThread() and is QMutex() compatible with python threads?

I'm using Python 3.7 (with PyQt5 for the GUI) on a Windows 10 computer. My application needs some multithreading. To do that, I use QThread(). I need to protect some code with a mutex. I figured I've got the following two options: protect it with a…
K.Mulier
  • 8,069
  • 15
  • 79
  • 141
2
votes
1 answer

How to correctly lock Qthreads in pyqt5 using Python3

I am relatively new to python, but was able to get a reasonably useful program to run to crunch a lot of data. I am able to run it over multiple sets of data sequentially using another python script to call the program serially, but I wanted to…
tdfoste
  • 21
  • 2
2
votes
2 answers

Wait for buttonPressed() slot to finish before executing buttonReleased()

I have a QPushButton that performs lengthy actions on pressed() and released() signals. How can I make sure that I finished executing all actions of the buttonPressed() slot, before executing the ones of the buttonReleased() slot? I have tried with…
mimo
  • 2,469
  • 2
  • 28
  • 49
2
votes
1 answer

Using QMutexLocker to Protect Shared Variables when Running Function with QtConcurrent

I do a discovery process in a background thread by using QtConcurrent: // Start the discover process in the background thread so it doesn't block the gui *m_Future = QtConcurrent::run(this,…
PhilBot
  • 748
  • 18
  • 85
  • 173
2
votes
1 answer

QMutex - does this mean I need a global mutex variable

I need to implement a mutex that works 2 ways: 1. protect a resource from across multiple classes, and 2. protect a resources from a method in a class that is a slot and may be re-entrant. For example (pseudo C++): Class A { function aaa() { …
TSG
  • 4,242
  • 9
  • 61
  • 121
1
2 3