I noticed that the code that doesn't compile with Qt5
#include <QMap>
class Foo {
public:
void setX(int x) { _x = x; }
private:
int _x;
};
int main() {
QMap<int, Foo> m;
m.value(1).setX(1);
}
#include <QMap>
class Foo {
public:
void setX(int x) { _x = x; }
private:
int _x;
};
int main() {
QMap<int, Foo> m;
m.value(1).setX(1);
}
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
const T
QMap::value(const Key
&key,
const T
&defaultValue
= T
()) const
const T QMap::value(const Key &key, const T &defaultValue = T()) const
To copy to clipboard, switch view to plain text mode
to
T
QMap::value(const Key
&key,
const T
&defaultValue
= T
()) const
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
const T
QMap::operator[](const Key
&key
) const
const T QMap::operator[](const Key &key) const
To copy to clipboard, switch view to plain text mode
Bookmarks