Qt
  1. Qt
  2. QTBUG-41004

New connect syntax fails with msvc in special corner cases

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: P2: Important P2: Important
    • Resolution: Out of scope
    • Affects Version/s: 5.4.0
    • Fix Version/s: None
    • Component/s: Core: Object Model
    • Labels:
      None
    • Environment:

      Windows, msvc

      Description

      Qt Creator stumbled over an issue where a connect with the new member fuction pointer based method compiled nicely but then failed at runtime with a

      QObject::connect: signal not found in Foo

      It is really much of a corner in this case which in addition seems to happen only with msvc. Not sure if this can be considered a compiler bug or a bug in Qt. Anyway I post this here for the records.

      Scenario: A class has a signal which overrides a virtual member function of its base class. When trying to connect to the signal of the derived class from outside the library (.dll) where the two classes "live", apparently a wrong method pointer is created. The result is the above message at runtime.

      Code in the library:

      ...
      class LIBSHARED_EXPORT A : public QObject
      {
      public:
          virtual void foo(int) {}
      };
      
      class LIBSHARED_EXPORT B : public A
      {
          Q_OBJECT
      signals:
          void foo(int);
          void bar();
      };
      ...
      

      Code outside the library:

          ...
          B b;
          QObject::connect(&b, &B::foo, &a, &QCoreApplication::quit); // causes runtime "QObject::connect: signal not found in B"
          QObject::connect(&b, &B::bar, &a, &QCoreApplication::quit); // succeeds
          ...
      

      See the attached msvcissue.zip for a working demo.

      1. msvcissue.zip
        2 kB
        Alessandro Portale

        Issue Links

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

          Activity

          Hide
          Olivier Goffart (Woboq GmbH) added a comment -

          signals are not supposed to be virtual. (moc even warns about that)

          Show
          Olivier Goffart (Woboq GmbH) added a comment - signals are not supposed to be virtual. (moc even warns about that)
          Hide
          Thiago Macieira added a comment -

          This is unfixable. The C++ standard says comparing PMFs to virtual functions is unspecified.

          5.10 [expr.eq] / 3

          Comparing pointers to members is defined as follows:
          [...]
          — If either is a pointer to a virtual member function, the result is unspecified.

          Show
          Thiago Macieira added a comment - This is unfixable. The C++ standard says comparing PMFs to virtual functions is unspecified. 5.10 [expr.eq] / 3 Comparing pointers to members is defined as follows: [...] — If either is a pointer to a virtual member function, the result is unspecified.

            People

            • Assignee:
              Thiago Macieira
              Reporter:
              Alessandro Portale
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Gerrit Reviews

                There are no open Gerrit changes