I noticed that the code that doesn't compile with Qt5

Qt Code:
  1. #include <QMap>
  2.  
  3. class Foo {
  4. public:
  5. void setX(int x) { _x = x; }
  6. private:
  7. int _x;
  8. };
  9.  
  10. int main() {
  11. QMap<int, Foo> m;
  12. m.value(1).setX(1);
  13. }
To copy to clipboard, switch view to plain text mode 

suddenly started to compile with Qt6. This is because of change in QMap::value signature from

Qt Code:
  1. const T QMap::value(const Key &key, const T &defaultValue = T()) const
To copy to clipboard, switch view to plain text mode 

to

Qt Code:
  1. T QMap::value(const Key &key, const T &defaultValue = T()) const
To copy to clipboard, switch view to plain text mode 

What is the rationale behind this change? As you can see, the Qt5 version prevented developers from making accidental mistakes, if they assumed that `T` is returned by reference.

There are probably more changes like this, another method that I am aware of, with the same effect, is

Qt Code:
  1. const T QMap::operator[](const Key &key) const
To copy to clipboard, switch view to plain text mode