How to expose a .Net (C#) event to Qt through com interop.



  • I am trying to expose a .Net event to QT using ActiveQT. I am using dumpcpp to convert my .tlb file to QT headers/classes. Here is my C# code.

    [ComVisible(true)]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [Guid("70417BD8-6A93-4F9E-ABF2-C20CC3D0C2F8")]
        public interface IWeatherEvents
        {
            void WeatherChanged(int x);
        }
    
    [ComVisible(true)]
        [ClassInterface(ClassInterfaceType.None)]
        [ComSourceInterfaces(typeof(IWeatherEvents))]
        [ProgId("DotNetDbLib.WeatherStation")]
        [Guid("ecb8c4cf-e662-49c2-af56-f4ec08ccde63")]
        public class WeatherStation : ServicedComponent, IWeatherStation
        {
            [ComVisible(false)]
            public delegate void WeatherChangedDelegate(int x);
    
            public event WeatherChangedDelegate WeatherChanged;
    
            public void CheckWeather()
            {
                WeatherChanged(20);
            }
        }
    
    [ComVisible(true)]
        [Guid("1010AFF8-292F-4D3D-921A-0BA650D1635C")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface IWeatherStation
        {
            void CheckWeather();
        }
    

    Posted below is some contents from the generated header file. I do not see any slots here. I was expecting a slot named WeatherChanged(int).

    class DOTNETDBLIB_EXPORT WeatherStation : public QAxObject
    {
    public:
        WeatherStation(QObject *parent = 0)
        : QAxObject(parent)
        {
            setControl("{ecb8c4cf-e662-49c2-af56-f4ec08ccde63}");
        }
    
        WeatherStation(IRemoteDispatch *iface)
        : QAxObject()
        {
            initializeFrom(iface);
            delete iface;
        }
    
        WeatherStation(IDisposable *iface)
        : QAxObject()
        {
            initializeFrom(iface);
            delete iface;
        }
    
        WeatherStation(IManagedObject *iface)
        : QAxObject()
        {
            initializeFrom(iface);
            delete iface;
        }
    
        WeatherStation(IServicedComponentInfo *iface)
        : QAxObject()
        {
            initializeFrom(iface);
            delete iface;
        }
    
        WeatherStation(IWeatherStation *iface)
        : QAxObject()
        {
            initializeFrom(iface);
            delete iface;
        }
    
        /*
        Property ToString
        */
        inline QString ToString() const; //Returns the value of ToString
    
        /*
        Method CheckWeather
        */
        inline void CheckWeather();
    
        /*
        Method Dispose
        */
        inline void Dispose();
    
        /*
        Method Equals
        */
        inline bool Equals(QVariant obj);
    
        /*
        Method GetComponentInfo
        */
        inline void GetComponentInfo(int& infoMask, QStringList& infoArray);
    
        /*
        Method GetHashCode
        */
        inline int GetHashCode();
    
        /*
        Method GetObjectIdentity
        */
        inline void GetObjectIdentity(QString& pBSTRGUID, int& AppDomainID, qlonglong& pCCW);
    
        /*
        Method GetSerializedBuffer
        */
        inline void GetSerializedBuffer(QString& pBSTR);
    
        /*
        Method GetType
        */
        inline mscorlib::_Type* GetType();
    
        /*
        Method RemoteDispatchAutoDone
        */
        inline QString RemoteDispatchAutoDone(QString s);
    
        /*
        Method RemoteDispatchNotAutoDone
        */
        inline QString RemoteDispatchNotAutoDone(QString s);
    
    // meta object functions
        static const QMetaObject staticMetaObject;
        virtual const QMetaObject *metaObject() const { return &staticMetaObject; }
        virtual void *qt_metacast(const char *);
    };
    

    Any guidance will be highly appreciated.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.