Unsolved Qt5 not recognise iteration over a standard map containers in C++17
-
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.
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
-
Does it compile? If yes, this might be clang code model which is wrongly detecting an error.
-
@Neoy easier?
std::map< char, int > dict{ { 'a', 27 }, { 'b', 3 } }; for ( const auto & pair : dict ) { std::cout << pair.first << " " << pair.second << std::endl; }
-
@JohanSolo It does compile, just not recognized by Qt5
-
@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. -
@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.
-
-
@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.