Definition of implicit copy constructor for 'QListSpecialMethodsBase<QString>' is deprecated because it has a user-declared destructor
-
Qt's official website tells users write code like this:
However, in QtCreator, the compilation environment warns:
How to remove this warning? It is better to modify the code rather than block this warning.
Thanks!@surfcius
Please don't post code screenshots, and not even give the link reference for it. I cannot copy from what you post to test, I have to type it all in by hand :( Post copied code.Ubuntu 24.04, Qt 6.4.2, gcc 13.2
#include <QCoreApplication> QStringList function() { QStringList types; types << "..."; return types; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList list = function(); return a.exec(); }
gives me no such warning, compiles and works. Does yours only give that warning from the code completion model inside Creator or do you get that warning when you actually compile?
-
In Qt, classes inherited from QList all have the same problem. For example, QModelIndexList. As shown in the following code. The reason is that QList defines the destructor, but does not define the copy constructor and copy assignment function, and clang will give a warning. It is not appropriate for users to modify the QList code themselves.
#include <QCoreApplication> #include <QModelIndexList> QModelIndexList function() { QModelIndexList indexes; return indexes; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QModelIndexList indexes = function(); return a.exec(); }
The code is listed above, and the environment screenshots are also given below:
-
Simply deactive this warning - it's a false positive.
The classes have a copy ctor as you can see in the documentation: https://doc.qt.io/qt-6/qlist.html#QList-2 -
C Christian Ehrlicher moved this topic from General and Desktop on
-
@surfcius , @Christian-Ehrlicher
In my code as pasted, Creator 13 I think (unless it's 11?), clang code completer too, I do not get that warning in the IDE. I don't believe I have touched any clang settings, I suspect my C++ is C++17. Why do I not get it?