Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt creator, CMake and c++17 code model.
Forum Updated to NodeBB v4.3 + New Features

Qt creator, CMake and c++17 code model.

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 3 Posters 1.3k Views 1 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.
  • M Offline
    M Offline
    mrFieldy
    wrote on last edited by
    #1

    Hi, everybody. I write code in qt-creator 4.8.0 + cmake (on linux). When using the std::get and std::variant functions, if std::visit is called in the same translation unit, the IDE generates many errors.

    class Foo {
       public:
        int a{1};
        int b{2};
        void set_a(const int new_a) { a = new_a; }
    };
    class Bat {
        int Arr[200]{};
    };
    int main() {
        int a;
        cin >> a;
        std::variant<Foo, Bat> var_1;
        if (a == 0)
            var_1 = Foo();
        else
            var_1 = Bat();
        std::variant<Foo, Bat> var_2;
        std::visit(
            [](auto& arg) {
            },
            var_2);
        std::get<Foo>(var_1).a = 444;
        std::get<Foo>(var_1).set_a(124);        // IDE throws an error (this argument to member function 'set_a' fas type 'const Foo', but function is not marked const)
        cout << std::get<Foo>(var_1).a << endl;
        return 0;
    }
    

    CMake script:

        cmake_minimum_required(VERSION 3.10)
        project(fast_test_2)
        set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
        set(CMAKE_CXX_STANDARD 17)
        add_executable(${PROJECT_NAME} "main.cpp")
    

    Despite this, the code is compiled (GCC 7.3). I have a section of code where std::get is actively used, and after adding a call to std::visit, qt-creator has colored the 2к code lines in red. How can I fix this?

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

      Hi and welcome to devnet,

      You may have unearthed a shortcoming from Qt Creator's current code model. You should check the bug report system to see if it's something known.

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        You may have unearthed a shortcoming from Qt Creator's current code model. You should check the bug report system to see if it's something known.

        M Offline
        M Offline
        mrFieldy
        wrote on last edited by
        #3

        @SGaist I didn't find my issue there. Should I write a bug report?

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

          One thing you can do is test the Qt Creator 4.9 Beta. If you still have the issue with it, then yes, please open a report.

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

          1 Reply Last reply
          0
          • aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            That's QTCREATORBUG-21873 now.

            Qt has to stay free or it will die.

            1 Reply Last reply
            1

            • Login

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