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

Dumpcpp generates wrong qt_metacall id

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.3.0
    • Active Qt
    • None
    • Windows

    Description

      Hello,

      I was trying to call C# code by using ActiveQt and a COM dll.
      After some trying i started noticing some weird problems:
      Sometimes the methods where not called and returning a default value.

      I did some testing and noticed the following, this my cs file:

       

      using System.Runtime.InteropServices;namespace SuperTest
      {
          [ComVisible( true )]
          [Guid( "DB1797F5-7198-4411-8563-D05F4E904956" )]
          [InterfaceType( ComInterfaceType.InterfaceIsDual )]
          public interface ISuperTest
          {
              string AA();
              string BB();
              string SS();
              string AS();
          }
          
          [ComVisible( true )]
          [Guid( "BA9AC84B-C7FC-41CF-8B2F-1764EB773D4B" )]
          [ClassInterface( ClassInterfaceType.None )]
          public class SuperTest : ISuperTest
          {
              string ISuperTest.AA()
              {
                  return "AA";
              }
      
              string ISuperTest.BB()
              {
                  return "BB";
              } 
              
              string ISuperTest.SS()
              {
                  return "SS";
              }
      
              string ISuperTest.AS()
              {
                  return "AS";
              }
          }
      }

      (.net framework 4.8 compiled in 64 bit)

      Then i generate the .cpp/.h files by using `dumpcpp.exe MyTLBFile.tlb`, and use this Qt main

      #include <QAxObject>
      #include <QApplication>
      #include "supertestcom.h"int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          qInfo() << "Hello World !"; 
      
          SuperTestCOM::SuperTest test;    
          qInfo() << test.AA();
          qInfo() << test.BB();
          qInfo() << test.SS();
          qInfo() << test.AS();    
         
          return 0;
      }

      and i get the following output

      Hello World !
      "AA"
      "BB"
      ""
      "AS"
      

      After inspecting the .h file generated by `dumpcpp.exe` i noticed that the id parameter of `qt_metacall` is wrong in the SuperTest::SS() function.

      inline QString SuperTest::AA()
      {
          QString qax_result;
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 8, _a);
          return qax_result;
      }
      
      inline QString SuperTest::AS()
      {
          QString qax_result;
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 9, _a);
          return qax_result;
      }
      
      inline QString SuperTest::BB()
      {
          QString qax_result;
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 10, _a);
          return qax_result;
      }
      
      inline bool SuperTest::Equals(const QVariant& obj)
      {
          bool qax_result;
          void *_a[] = {(void*)&qax_result, (void*)&obj};
          qt_metacall(QMetaObject::InvokeMetaMethod, 11, _a);
          return qax_result;
      }
      
      inline int SuperTest::GetHashCode()
      {
          int qax_result;
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 12, _a);
          return qax_result;
      }
      
      inline mscorlib::_Type* SuperTest::GetType()
      {
          mscorlib::_Type* qax_result = 0;
      #ifdef QAX_DUMPCPP_MSCORLIB_H
          qRegisterMetaType<mscorlib::_Type*>("mscorlib::_Type*");
          qRegisterMetaType<mscorlib::_Type>("mscorlib::_Type");
      #endif
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 13, _a);
          return qax_result;
      }
      
      inline QString SuperTest::SS()
      {
          QString qax_result;
          void *_a[] = {(void*)&qax_result};
          qt_metacall(QMetaObject::InvokeMetaMethod, 14, _a);
          return qax_result;
      }
      

      `qt_metacall(QMetaObject::InvokeMetaMethod, 14, _a);` should be `qt_metacall(QMetaObject::InvokeMetaMethod, 11, _a);`
      If i change it to 11 and recompile it works.

      Hello World !
       "AA"
       "BB"
       "SS"
       "AS"
      

      So i guess that there is some kind of issue where the method names are sorted, but their id's are not changed accordingly.

      Tested in Qt 6.2.0, 6.3.0 and 5.9.9.

      Best regards.
      Gundz.

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            gundz gundz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes