Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3220318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:44:51+00:00 2026-05-17T15:44:51+00:00

I’m writing a wrapper in .NET (C++/CLI) to be able to use some native

  • 0

I’m writing a wrapper in .NET (C++/CLI) to be able to use some native C++ Qt code in .NET. How can I map a Qt signal into a managed .NET event, so that when my Qt code fires off a signal, I can bring this forward to the .NET code.

My Managed class defines the event, but if I try to use the normal QObject::connect method to hook up to the signal, it requires a QObject * receiver… I guess I have to do some magic marshalling of some sorts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:44:51+00:00Added an answer on May 17, 2026 at 3:44 pm

    Define normal unmanaged Qt event handler. From this handler, raise managed event.

    Edit: if you have previous experience in Qt, you know how to handle Qt signals in unmanaged class. Don’t try to make this class managed. Instead of this, write C++/CLI wrapper which contains this QObject-derived class.

    Edit 2. Create C++/CLI Console application, call it test1, and add the following code to it:

    test1.cpp:

    #include "stdafx.h"
    #include "ManagedClass.h"
    
    using namespace System;
    
    int main(array ^args)
    {
        ManagedClass^ c = gcnew ManagedClass();
        c->Test();
    
        return 0;
    }
    

    ManagedClass.h:

    #pragma once
    
    class UnmanagedClass;
    
    // Wrapper
    ref class ManagedClass
    {
    public:
        ManagedClass(void);
        ~ManagedClass();
        !ManagedClass();
        void Test();
        void Callback();
    
    private:
        UnmanagedClass* m_pUnmanagedClass;
    };
    

    ManagedClass.cpp:

    #include "StdAfx.h"
    #include "ManagedClass.h"
    #include "UnmanagedClass.h"
    
    ManagedClass::ManagedClass(void)
    {
        m_pUnmanagedClass = new UnmanagedClass(this);
    }
    
    ManagedClass::~ManagedClass()
    {
        this->!ManagedClass();
        GC::SuppressFinalize(this);
    }
    
    ManagedClass::!ManagedClass()
    {
        if ( m_pUnmanagedClass )
        {
            delete m_pUnmanagedClass;
            m_pUnmanagedClass = NULL;
        }
    }
    
    
    void ManagedClass::Test()
    {
        m_pUnmanagedClass->Test();
    }
    
    void ManagedClass::Callback()
    {
        Console::WriteLine(L"This text is printed from managed wrapper function, called from unmanaged class.");
        Console::WriteLine(L"Here you can raise managed event for .NET client.");
        Console::WriteLine(L"Let's say that UnmanagedClass is QObject-derived, and this funcstion");
        Console::WriteLine(L"is called from UnmanagedClass Qt event handler - this is what you need.");
    }
    

    UnmanagedClass.h:

    #pragma once
    
    #include 
    using namespace System;
    
    
    ref class ManagedClass;
    
    // Wrapped native class
    class UnmanagedClass
    {
    public:
        UnmanagedClass(ManagedClass^ pWrapper);
        ~UnmanagedClass(void);
        void Test();
    
    private:
        gcroot m_pWrapper;
    };
    

    UnmanagedClass.cpp:

    #include "StdAfx.h"
    #include "UnmanagedClass.h"
    #include "ManagedClass.h"
    
    UnmanagedClass::UnmanagedClass(ManagedClass^ pWrapper)
    {
        m_pWrapper = pWrapper;
    }
    
    UnmanagedClass::~UnmanagedClass(void)
    {
    }
    
    void UnmanagedClass::Test()
    {
        m_pWrapper->Callback();
    }
    

    This gives you idea how unmanaged class and managed wrapper can play together. If you know Qt programming and know how to raise .NET event from ref C++/CLI class, this is enough to accomplish your task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.