Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-126649

QObject::connect: Document that you must not mix PMF- and string-based APIs

    XMLWordPrintable

Details

    • All
    • 27a3229626249a100d8e6fa495927715aba6963d

    Description

      If you connect using the PMF-based API and disconnect using strings, then you will silently get a memory leak:

      For instance code like this will just leak memory indefinitely:

          MyQObject *o2 = new MyQObject;
          MyQObject *o1 = new MyQObject;
       
          forever {
              QObject::connect(o2, &QObject::destroyed, o1, &MyQObject::testSlot);
              o2->disconnect(o1, SLOT(testSlot(QObject*)));
          } 
      

      This is an easy trap to fall into, especially when porting existing string-based code to use the new API and finding that there is no equivalent for all the function calls. And it was recently the cause of a memory leak in Qt itself.

      There currently does not appear to be any mention of this in the documentation, so there should probably be warnings in all relevant places that the syntaxes need to match and the application should ideally pick either one or the other.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vhilshei Volker Hilsheimer
            esabraha Eskil Abrahamsen Blomfeldt
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes