Qt World Summit: Submit your Presentation

Not able to resolve std::atomic operations in Qt 5.15.2

  • Hello Team,

    I am trying to using C++ atomic variables in Qt 5.15.2. But I am getting an error "no template named 'atomic' in namespace std".
    Please find below sample code

    #include <atomic>
    std::atomic<bool> ready (false);

    Could anyone please help me why am not able to use atomic in my Qt

  • Lifetime Qt Champion


    Which OS are you on ?
    Did you change the C++ standard to use in your .pro file ?

  • @SGaist
    I am using Ubuntu-18.04.1

    In .pro file, we tried with below configurations, but no luck
    CONFIG += c++11
    QMAKE_CXXFLAGS +=-std=c++0x

    g++ version -
    Using built-in specs.
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
    Thread model: posix
    gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)

  • Lifetime Qt Champion

    Can you build that file directly on the command line ?

  • @SGaist
    Yes, I am able to build successfully from command line in Ubuntu Terminal

  • Lifetime Qt Champion

    Can you provide a minimal main.cpp and .pro file that shows the issue ?

  • @SGaist
    My pro file looks like

    QT += quick
    CONFIG += c++11
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    SOURCES += \
    INCLUDEPATH += /usr/include/
    RESOURCES += qml.qrc
    # Additional import path used to resolve QML modules in Qt Creator's code model
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    main.cpp looks like

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <iostream>
    #include <atomic>
    std::atomic<bool> ready (false);
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
        }, Qt::QueuedConnection);
        return app.exec();

    Not resolving <iostream> and <atomic> directives

  • Moderators

    @Praveen-Illa said in Not able to resolve std::atomic operations in Qt 5.15.2:

    Not resolving <iostream> and <atomic> directives

    Install the c++ development packages for your platform and compiler, possibly for the atomic library, drop the superfluous INCLUDEPATH+= from your project and link against the atomic library if necessary: LIBS += -latomic.

Log in to reply