Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Trying to use C++17 parallel algorithms with Qt



  • Hi
    I'm trying to use C++17 parallel algorithms with Qt5.15. I'm using GCC9.3 on CentOS 7.0
    I've installed oneapi-tbb-2021.1.1,
    added

    export CPATH=<tbb_install_path>/oneapi-tbb-2021.1.1/include:<tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi:<tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb
    export LD_LIBRARY_PATH=<tbb_install_path>/oneapi-tbb-2021.1.1/lib/intel64/gcc4.8:$LD_LIBRARY_PATH
    

    When I'm trying to compile cpp file with #include <execution> has error:

    <tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb/profiling.h:231:22: error: expected unqualified-id before 'const'
      231 |     static void emit(const std::string &) { }
          |                      ^~~~~
    <tbb_install_path>/oneapi-tbb-2021.1.1/include/oneapi/tbb/profiling.h:231:22: error: expected ')' before 'const'
      231 |     static void emit(const std::string &) { }
          |                     ~^~~~~
          |                      )
    

    I suspect this is caused by "emit" name clashing with Qt emit. How can I solve this issue?
    Thank you.


  • Moderators

    Use CONFIG+=no_keywords in your qmake file: doc.



  • @sierdzio said in Trying to use C++17 parallel algorithms with Qt:

    no_keywords

    Thank you very much for your reply.
    From my understanding, this will require to change occurrences of signals to Q_SIGNALS and slots to Q_SLOTS in all of Qt code?
    Is there a way to have some sort of "ignore list" for specific files?

    I'll try this "fix-it" https://github.com/KDE/clazy/blob/master/docs/checks/README-qt-keywords.md see how that goes.

    Thank you again


  • Moderators

    Yes, no_keywords will work globally for the whole project.

    Locally I think you can just remove emit per file like this:

    // in c++ code:
    #undef emit
    


  • Thank you very much again

    Our build system doesn't use qmake and calls "moc" directly. I don't know where I can add CONFIG += no_keywords. How can I add this switch to "moc" without make?
    I added indef as you suggested.
    Now I'm getting the following error:

    In file included from <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend.h:14,
                     from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/algorithm_impl.h:25,
                     from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/glue_execution_defs.h:52,
                     from  <install_dir>//gcc/v9.3.0/include/c++/9.3.0/execution:32,
                     from policies.hpp:21,
                     from bench_t.cpp:27:
     <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend_tbb.h: In function 'void __pstl::__par_backend::__cancel_execution()':
     <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend_tbb.h:70:10: error: 'tbb::task' has not been declared
       70 |     tbb::task::self().group()->cancel_group_execution();
          |          ^~~~
    In file included from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/parallel_backend.h:14,
                     from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/algorithm_impl.h:25,
                     from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/pstl/glue_execution_defs.h:52,
                     from  <install_dir>/gcc/v9.3.0/include/c++/9.3.0/execution:32,
    

    Is "task" some sort of special keyword too or it can't find correct headers?


  • Moderators

    I don't think task is a keyword.

    Our build system doesn't use qmake and calls "moc" directly. I don't know where I can add CONFIG += no_keywords. How can I add this switch to "moc" without make?

    Add QT_NO_KEYWORDS to compiler defines (-DQT_NO_KEYWORDS). This has nothing to do with moc.



  • @sierdzio said in Trying to use C++17 parallel algorithms with Qt:

    QT_NO_KEYWORDS

    From your link to the docs: "CONFIG += no_keywords tells Qt not to define the moc keywords signals, slots, and emit, because these names will be used by a 3rd party library," so I assumed it's moc command.
    Isn't it moc that translates all connection/slot related logic to C++ ?


  • Lifetime Qt Champion

    @Eukaryote said in Trying to use C++17 parallel algorithms with Qt:

    Isn't it moc that translates all connection/slot related logic to C++ ?

    It is, but the compiler generates the machine code.



  • Just to summerise the issue in case anyone else will be encounter something similar.

    1. I want to use <execution> header from C++17 with GCC9
    2. That requires Intel's TBB library and includes
    3. Both Qt and TBB use emit that is replaced by Qt. To solve this locally, I've undefined "emit" before using <execution> header. The general solution is to use -DQT_NO_KEYWORDS and replace emit/signal with Q_SIGNALS/ Q_SLOTS
    4. gcc9 uses task class from TBB that was deprecated in 2020. The solution is to use TBB 2019 or a newer GCC.

Log in to reply