Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Not able to resolve std::atomic operations in Qt 5.15.2
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Praveen.Illa
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        P Offline
        P Offline
        Praveen.Illa
        wrote on last edited by Praveen.Illa
        #3

        @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.
        COLLECT_GCC=g++
        COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
        OFFLOAD_TARGET_NAMES=nvptx-none
        OFFLOAD_TARGET_DEFAULT=1
        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)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you build that file directly on the command line ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you build that file directly on the command line ?

            P Offline
            P Offline
            Praveen.Illa
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              P 1 Reply Last reply
              0
              • SGaistS SGaist

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

                P Offline
                P Offline
                Praveen.Illa
                wrote on last edited by
                #7

                @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 += \
                        main.cpp
                
                INCLUDEPATH += /usr/include/
                
                DEFINES += LINUX
                
                RESOURCES += qml.qrc
                
                # Additional import path used to resolve QML modules in Qt Creator's code model
                QML_IMPORT_PATH =
                
                # Additional import path used to resolve QML modules just for Qt Quick Designer
                QML_DESIGNER_IMPORT_PATH =
                
                # 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[])
                {
                    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                
                    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)
                            QCoreApplication::exit(-1);
                    }, Qt::QueuedConnection);
                    engine.load(url);
                
                    return app.exec();
                }
                

                Not resolving <iostream> and <atomic> directives

                kshegunovK 1 Reply Last reply
                0
                • P Praveen.Illa

                  @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 += \
                          main.cpp
                  
                  INCLUDEPATH += /usr/include/
                  
                  DEFINES += LINUX
                  
                  RESOURCES += qml.qrc
                  
                  # Additional import path used to resolve QML modules in Qt Creator's code model
                  QML_IMPORT_PATH =
                  
                  # Additional import path used to resolve QML modules just for Qt Quick Designer
                  QML_DESIGNER_IMPORT_PATH =
                  
                  # 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[])
                  {
                      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                  
                      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)
                              QCoreApplication::exit(-1);
                      }, Qt::QueuedConnection);
                      engine.load(url);
                  
                      return app.exec();
                  }
                  

                  Not resolving <iostream> and <atomic> directives

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @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.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved