Search code examples
c++qtatomic

Qt 4 QAtomicInt: How to load() and store()?


I have the following code which works for Qt 5:

QAtomicInt myAtomicInt;
myAtomicInt.load();
myAtomicInt.store(123);

Now I would like to write the same code for Qt 4. However, the Qt 4 version of QAtomicInt does not have member functions load() and store(). How to proceed? Thanks !


Solution

  • QAtomicInt::load() gets the value using relaxed memory ordering, so fetchAndAddRelaxed(0) would do the same in Qt 4.

    QAtomicInt::store(int) stores the value using relaxed memory ordering, so fetchAndStoreRelaxed(int) would do the same in Qt 4.