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

New connect syntax fails with msvc in special corner cases

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 5.4.0
    • Core: Object Model
    • None
    • 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.

      Attachments

        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

            People

              thiago Thiago Macieira
              portale Alessandro Portale
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes