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
1
vote
1 answer

What is the difference between "thread and QThread" and "mutex and QMutex" in Python?

I'm doing research on multithreads in python. Can you explain the differences between "thread and QThread" and "mutex and QMutex"?
tirit
  • 33
  • 2
1
vote
2 answers

QMutex: destroying locked mutex

Given the following code: #include #include #include #include #include #include #include #include #include #include class…
canellas
  • 491
  • 5
  • 17
1
vote
1 answer

"Attempting to reference a deleted function" after adding QMutex to class

I am building an application with Qt5. My program builds and runs fine, but there is a collision between two threads accessing a data structure. I have a QList of CanMessage objects, and I want to protect some data inside of it using a QMutex.…
Erik Johnson
  • 858
  • 1
  • 7
  • 29
1
vote
1 answer

Crash creating QMutexLocker from child QThread

I have QMutex and QQueue as member in QThread based class. I'm locking QMutex (by QMutexLocker) in popEvent and pushEvent metods. When I lock it in push method called from main thread it works. When I call pop function from child thread loop it…
patrykbajos
  • 384
  • 3
  • 17
1
vote
1 answer

Qt , How to lock SQLite database for multiple operation

I have a QML application which user intract with. There is a timer that listen to server for work order then insert all info to SQLite db in application.Also user make change on data (update,delete etc...) in SQLite. My question is , How to prevent…
Kevin yudo
  • 233
  • 4
  • 15
1
vote
1 answer

using data shared between multiple threads in a QAbstractTableModel

I have a singleton class implemented using Q_GLOBAL_STATIC that contains a data structure that has to be accessed from multiple threads, I implemented accessor functions in the class, that would lock a mutex before accessing the data, so that all…
Mike
  • 8,055
  • 1
  • 30
  • 44
1
vote
0 answers

Unable to obtain a lock on a QMutex

The application I'm working on at the moment is heavily multi-threaded, with a number of resources that are shared between threads. I use QMutexes in order to protect the shared resources, though in practice there should only very rarely be…
Eos Pengwern
  • 1,467
  • 3
  • 20
  • 37
1
vote
3 answers

Handling with Critical Sections in Qt

I've searched a lot for an answer to this question, but it seems there isn't any. I'm using Qt 5.2.0 to make a TCP client with winsocks2. The language in use is C++. To make the connection loop (where I call send() and write()) I'm using QThread…
MuriloGK
  • 33
  • 2
  • 9
1
vote
3 answers

QMutex ,wait here if a thread is in function

I just want to implement the code like below. QString Class1::getNonce() { //if some thread is getting nonce wait here until it finishes the its own job. mutex.lock(); QString…
1
vote
1 answer

Qt/C++ shared variables and visibility across class instances

I'm struggling with something very basic that I'm hoping that someone can help clarify. Take for example this pseudo C++ code: class T { public QMutex M; int I; } If I instantiate this class three times (as 3 threads), are there 3…
TSG
  • 4,242
  • 9
  • 61
  • 121
1
vote
1 answer

QMutex - protect within a thread but not across threads

I need to protect a resource from being interrupted, in this case writing to a socket. I have a class, TelnetServer, which is instantiated many times (once per used connection). I want to prevent a write to a single user from being interrupted by…
TSG
  • 4,242
  • 9
  • 61
  • 121
1
vote
2 answers

QMutex lock in one thread and unlock in the other thread

Am I allowed to use the QMutex in the strange way: lock the QMutex in one thread, then unlock it in the other thread?
osgx
  • 90,338
  • 53
  • 357
  • 513
1
vote
1 answer

QMutex with QThread - Segmentation fault

I have a C++ Qt program that uses QThread with pause/resume mechanism implemented using QMutex and QWaitCondition. That's how it looks: MyThread.h: class MyThread : public QThread { Q_OBJECT public: MyThread(); void…
ahawkthomas
  • 656
  • 3
  • 13
  • 26
1
vote
0 answers

'class QMutex' has no member named 'EnterCriticalSection'

I'm using QT 4.8 and whenever i do a simple usage of QMutex, I get the compilation error of: 'class QMutex' has no member named 'EnterCriticalSection' Sample: void classA::write (int x) { mutex->lock() ... do something …
Tony Huy
  • 11
  • 1
0
votes
5 answers

Do I need a QMutex for variable that is accessed by single statement?

In this document, a QMutex is used to protect "number" from being modified by multiple threads at same time. I have a code in which a thread is instructed to do different work according to a flag set by another thread. //In thread1 if(flag) …
William
  • 761
  • 2
  • 10
  • 27