error: no matching function for call to 'QList<QObject *>::removeAll()'
-
wrote on 14 Sept 2023, 03:39 last edited by
I have a class that has several private members that have type QObjectList:
QObjectList A, B, C, D;
The class has a delete function for each of these object lists that deletes each item in the list, then removes them from the list:
void ClassName::DeleteA() { for( int i = A.count(); i--; ) delete *Output[ i ]; A.removeAll(); }
I'm getting a "error: no matching function for call " error for the call to removeAll() or each function. The error remains if I remove the delete loop and only have the removeAll() call.
If it helps, I'm using the Desktop Qt 5.15.2 MinGW 32-bit compiler.
-
-
I have a class that has several private members that have type QObjectList:
QObjectList A, B, C, D;
The class has a delete function for each of these object lists that deletes each item in the list, then removes them from the list:
void ClassName::DeleteA() { for( int i = A.count(); i--; ) delete *Output[ i ]; A.removeAll(); }
I'm getting a "error: no matching function for call " error for the call to removeAll() or each function. The error remains if I remove the delete loop and only have the removeAll() call.
If it helps, I'm using the Desktop Qt 5.15.2 MinGW 32-bit compiler.
wrote on 14 Sept 2023, 04:29 last edited by@Calvin-H-C said in error: no matching function for call to 'QList<QObject *>::removeAll()':
I have a class that has several private members that have type QObjectList:
QObjectList A, B, C, D;
The class has a delete function for each of these object lists that deletes each item in the list, then removes them from the list:
void ClassName::DeleteA() { for( int i = A.count(); i--; ) delete *Output[ i ];
Not that this is particularly tricky code, but
qDeleteAll() is another option.A.removeAll();
}You probably want QList::clear().
QList::removeAll() takes a parameter specifying a value to remove. -
I have a class that has several private members that have type QObjectList:
QObjectList A, B, C, D;
The class has a delete function for each of these object lists that deletes each item in the list, then removes them from the list:
void ClassName::DeleteA() { for( int i = A.count(); i--; ) delete *Output[ i ]; A.removeAll(); }
I'm getting a "error: no matching function for call " error for the call to removeAll() or each function. The error remains if I remove the delete loop and only have the removeAll() call.
If it helps, I'm using the Desktop Qt 5.15.2 MinGW 32-bit compiler.
wrote on 14 Sept 2023, 04:34 last edited by Pl45m4@Calvin-H-C said in error: no matching function for call to 'QList<QObject *>::removeAll()':
"error: no matching function for call "
Because there is no such function in the way you are trying to use it.
QObjectList
is an alias for a list storingQObject
pointers, so:QList<QObject* >
.
QList
has the functionremoveAll
which signature is:QList::removeAll(const AT &t)
(https://doc.qt.io/qt-6/qlist.html#removeAll)Since you want to delete every member of that list manually before, why dont you simply call
A.clear()
?Or use it together with
takeAt(i)
likefor( int i = A.count(); i--; ){ auto obj = A.takeAt(i); delete obj; } A.clear();
@jeremy_k took me a while to write this post. You were faster sending the answer :P
-
@Calvin-H-C said in error: no matching function for call to 'QList<QObject *>::removeAll()':
"error: no matching function for call "
Because there is no such function in the way you are trying to use it.
QObjectList
is an alias for a list storingQObject
pointers, so:QList<QObject* >
.
QList
has the functionremoveAll
which signature is:QList::removeAll(const AT &t)
(https://doc.qt.io/qt-6/qlist.html#removeAll)Since you want to delete every member of that list manually before, why dont you simply call
A.clear()
?Or use it together with
takeAt(i)
likefor( int i = A.count(); i--; ){ auto obj = A.takeAt(i); delete obj; } A.clear();
@jeremy_k took me a while to write this post. You were faster sending the answer :P
wrote on 14 Sept 2023, 04:43 last edited by@Pl45m4 said in error: no matching function for call to 'QList<QObject *>::removeAll()':
@jeremy_k took me a while to write this post. You were faster sending the answer :P
Competition-grade keyboard!
-
-
wrote on 15 Sept 2023, 00:44 last edited by
@SGaist said in error: no matching function for call to 'QList<QObject *>::removeAll()':
qDeleteAll(myContainer);
myContainer.clear();Thanks to everyone, but especially for this concise suggestion.
Somewhere I did see that removeAll() was for all of a specific value, but somehow forgot that little detail. Just all part of using MFC for many years before learning QT in my late 50s.
-
@SGaist said in error: no matching function for call to 'QList<QObject *>::removeAll()':
qDeleteAll(myContainer);
myContainer.clear();Thanks to everyone, but especially for this concise suggestion.
Somewhere I did see that removeAll() was for all of a specific value, but somehow forgot that little detail. Just all part of using MFC for many years before learning QT in my late 50s.
wrote on 15 Sept 2023, 12:09 last edited by@Calvin-H-C
The sample code at https://doc.qt.io/qt-6/qtalgorithms.html#qDeleteAll gives just that code :) -
1/7