Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to expose a .Net (C#) event to Qt through com interop.
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 538 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinayan
    wrote on 19 Dec 2016, 06:46 last edited by A Former User
    #1

    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.

    1 Reply Last reply
    0

    1/1

    19 Dec 2016, 06:46

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved