@ChrisW67 Thank you! Yes, I thought about smart pointers as well but I am (yet) not very familiar with it and don't know which one is correct. Currently we work most of the time with raw pointers and the old Qt3 QPtrList .
@J-Hilk Thanks! Ok, so removing the deleted move constructor and move assignment operator works. I was marking it delete because I wanted to avoid implicitly generated move semantics, but now I understand that it won't be generated by itself if I have a copy constructor already.
It is still weird that QList was giving error for deleted move semantics when it is not using move semantics at all.
Unless you have some hardcore use case, perhaps you don't need to cache at all? SQLite is pretty fast, and Qt comes with QSqlQueryModel / TableModel helper classes. In my (limited :D) experience, it works really well and fast, even on slow hardware.
I'm not completely ignorant in the ways of C++ though, I'm not 100% certain, but fairly confident that:
Const 1) Ensures the returned value can't be modified,
the use cases of which I'll admit I'm not really privy to.
Use case 1:
Allow the caller to read the data without creating a copy, AND
Make sure the data is read-only
If the returned reference is non-const, the caller will be able to directly modify the object's internal memory. This breaks encapsulation.
Use case 2: Allow the function to be called in another const function.
There's a const and a non-const version of QList::operator(int):
T & operator(int i)
const T & operator(int i) const
Version #1 allows the caller to modify the QList element. However, it cannot be called in a const function -- it will cause the error in your original post. Thus, version #2 is required for use in const functions.
I know that its only really useful when dealing with user defined classes and returning by value reference (which is the case in your example) to prevent memory modification if desired.
(Acknowledging your typo)
Why would it be "only really useful when dealing with user defined classes"? Notice that QList::at() returns a const reference.
I do remember seeing something about this being somewhat obsolete in C++ 11 (or was it 17) and forward, though I'm not sure why.
Returning const references is defintiely not obsolete.