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 982 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 16 Nov 2023, 15:44 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

    J 1 Reply Last reply 16 Nov 2023, 17:41
    0
    • J Offline
      J Offline
      JohanSolo
      wrote on 16 Nov 2023, 16:07 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 18 Nov 2023, 09:52
      0
      • N Neoy
        16 Nov 2023, 15:44

        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

        J Offline
        J Offline
        JoeCFD
        wrote on 16 Nov 2023, 17:41 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 18 Nov 2023, 10:03
        0
        • J JohanSolo
          16 Nov 2023, 16:07

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

          N Offline
          N Offline
          Neoy
          wrote on 18 Nov 2023, 09:52 last edited by
          #4

          @JohanSolo It does compile, just not recognized by Qt5

          J 1 Reply Last reply 18 Nov 2023, 09:55
          0
          • N Neoy
            18 Nov 2023, 09:52

            @JohanSolo It does compile, just not recognized by Qt5

            J Offline
            J Offline
            JonB
            wrote on 18 Nov 2023, 09:55 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 18 Nov 2023, 10:15
            0
            • J JoeCFD
              16 Nov 2023, 17:41

              @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 18 Nov 2023, 10:03 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
              • J JonB
                18 Nov 2023, 09:55

                @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 18 Nov 2023, 10:15 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~

                J 1 Reply Last reply 18 Nov 2023, 13:50
                0
                • N Neoy
                  18 Nov 2023, 10:15

                  @JonB I'm using

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

                  Thanks~

                  J Offline
                  J Offline
                  JonB
                  wrote on 18 Nov 2023, 13:50 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

                  1/8

                  16 Nov 2023, 15:44

                  • Login

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