Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: no matching function for call to 'QList<QObject *>::removeAll()'
Forum Update on Monday, May 27th 2025

error: no matching function for call to 'QList<QObject *>::removeAll()'

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 611 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Calvin H-C
    wrote on 14 Sept 2023, 03:39 last edited by
    #1

    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.

    J P 2 Replies Last reply 14 Sept 2023, 04:29
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Sept 2023, 19:02 last edited by
      #5

      Hi,

      Here is a shorter version:

      qDeleteAll(myContainer);
      myContainer.clear();
      

      qDeleteAll

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply 15 Sept 2023, 00:44
      2
      • C Calvin H-C
        14 Sept 2023, 03:39

        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.

        J Offline
        J Offline
        jeremy_k
        wrote on 14 Sept 2023, 04:29 last edited by
        #2

        @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.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        1
        • C Calvin H-C
          14 Sept 2023, 03:39

          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.

          P Offline
          P Offline
          Pl45m4
          wrote on 14 Sept 2023, 04:34 last edited by Pl45m4
          #3

          @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 storing QObject pointers, so: QList<QObject* >.
          QList has the function removeAll 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) like

          for( 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


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          J 1 Reply Last reply 14 Sept 2023, 04:43
          0
          • P Pl45m4
            14 Sept 2023, 04:34

            @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 storing QObject pointers, so: QList<QObject* >.
            QList has the function removeAll 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) like

            for( 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

            J Offline
            J Offline
            jeremy_k
            wrote on 14 Sept 2023, 04:43 last edited by
            #4

            @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!

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 14 Sept 2023, 19:02 last edited by
              #5

              Hi,

              Here is a shorter version:

              qDeleteAll(myContainer);
              myContainer.clear();
              

              qDeleteAll

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              C 1 Reply Last reply 15 Sept 2023, 00:44
              2
              • S SGaist
                14 Sept 2023, 19:02

                Hi,

                Here is a shorter version:

                qDeleteAll(myContainer);
                myContainer.clear();
                

                qDeleteAll

                C Offline
                C Offline
                Calvin H-C
                wrote on 15 Sept 2023, 00:44 last edited by
                #6

                @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.

                JonBJ 1 Reply Last reply 15 Sept 2023, 12:09
                0
                • C Calvin H-C
                  15 Sept 2023, 00:44

                  @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.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 15 Sept 2023, 12:09 last edited by
                  #7

                  @Calvin-H-C
                  The sample code at https://doc.qt.io/qt-6/qtalgorithms.html#qDeleteAll gives just that code :)

                  1 Reply Last reply
                  0
                  • S SGaist has marked this topic as solved on 15 Sept 2023, 19:11

                  1/7

                  14 Sept 2023, 03:39

                  • Login

                  • Login or register to search.
                  1 out of 7
                  • First post
                    1/7
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved