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 Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 623 Views 3 Watching
  • 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 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.

    jeremy_kJ Pl45m4P 2 Replies Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      2
      • C Calvin H-C

        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.

        jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on 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

          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.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on 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

          jeremy_kJ 1 Reply Last reply
          0
          • Pl45m4P 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 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

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              2
              • SGaistS SGaist

                Hi,

                Here is a shorter version:

                qDeleteAll(myContainer);
                myContainer.clear();
                

                qDeleteAll

                C Offline
                C Offline
                Calvin H-C
                wrote on 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
                0
                • C Calvin H-C

                  @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 Online
                  JonBJ Online
                  JonB
                  wrote on 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
                  • SGaistS SGaist has marked this topic as solved on

                  • Login

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