Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. Qt5 not recognise iteration over a standard map containers in C++17

Qt5 not recognise iteration over a standard map containers in C++17

Scheduled Pinned Locked Moved Unsolved Qt in Education
8 Posts 4 Posters 985 Views
  • 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.
  • N Offline
    N Offline
    Neoy
    wrote on last edited by
    #1

    Hi, I'm new to Qt5. I trying to iterate through std::map by C++ 17 style. However, the key and value seem not to be recognized by the IDE.

    f5eb2504-3c81-4503-88c7-3c164d8aa978-Screenshot from 2023-11-16 23-43-18.png

    std ::map<char, int> my_dict{{'a', 27}, {'b', 3}};
    for (const auto &[key, value] : my_dict) {

    std::cout << key << " has value " << value << std::endl;
    

    }

    /home/neoy/Pictures/Screenshot from 2023-11-16 23-43-18.png

    JoeCFDJ 1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by JohanSolo
      #2

      Does it compile? If yes, this might be clang code model which is wrongly detecting an error.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      N 1 Reply Last reply
      0
      • N Neoy

        Hi, I'm new to Qt5. I trying to iterate through std::map by C++ 17 style. However, the key and value seem not to be recognized by the IDE.

        f5eb2504-3c81-4503-88c7-3c164d8aa978-Screenshot from 2023-11-16 23-43-18.png

        std ::map<char, int> my_dict{{'a', 27}, {'b', 3}};
        for (const auto &[key, value] : my_dict) {

        std::cout << key << " has value " << value << std::endl;
        

        }

        /home/neoy/Pictures/Screenshot from 2023-11-16 23-43-18.png

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        @Neoy easier?

            std::map< char, int > dict{ { 'a', 27 }, { 'b', 3 } };
            for ( const auto & pair : dict ) {
                std::cout << pair.first  << " " << pair.second << std::endl;
            }
        
        N 1 Reply Last reply
        0
        • JohanSoloJ JohanSolo

          Does it compile? If yes, this might be clang code model which is wrongly detecting an error.

          N Offline
          N Offline
          Neoy
          wrote on last edited by
          #4

          @JohanSolo It does compile, just not recognized by Qt5

          JonBJ 1 Reply Last reply
          0
          • N Neoy

            @JohanSolo It does compile, just not recognized by Qt5

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Neoy
            Not "Qt5", you mean either/both of Qt Creator or the Code Completion component you are using inside it do not recognise the construct when editing source code. Don't know what version of Qt Creator you are using.

            N 1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              @Neoy easier?

                  std::map< char, int > dict{ { 'a', 27 }, { 'b', 3 } };
                  for ( const auto & pair : dict ) {
                      std::cout << pair.first  << " " << pair.second << std::endl;
                  }
              
              N Offline
              N Offline
              Neoy
              wrote on last edited by
              #6

              @JoeCFD Thanks. But I want to increase the readability of the code, especially when there is a map as the value of another map, which makes the following code appear too many "it.first.seocond...". that is hard to read.

              1 Reply Last reply
              1
              • JonBJ JonB

                @Neoy
                Not "Qt5", you mean either/both of Qt Creator or the Code Completion component you are using inside it do not recognise the construct when editing source code. Don't know what version of Qt Creator you are using.

                N Offline
                N Offline
                Neoy
                wrote on last edited by
                #7

                @JonB I'm using

                Qt Creator 4.11.0
                Based on Qt 5.12.8 (GCC 9.3.0, 64 bit)

                Thanks~

                JonBJ 1 Reply Last reply
                0
                • N Neoy

                  @JonB I'm using

                  Qt Creator 4.11.0
                  Based on Qt 5.12.8 (GCC 9.3.0, 64 bit)

                  Thanks~

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @Neoy
                  So, since this is a debugger or Creator issue and not a Qt one, you may find that a newer version handles this feature. Creator is now up to version 11 and you have version 4. Qt 5.12 is 5 years old now. It's from 2018, and you are reporting an issue with C++ 17. Just saying... Also your issue is in whatever is being used as your code model, make sure that is as up-to-date as it can be.

                  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