Home

QMfcApp Class Reference

The QMfcApp class provides merging of the MFC and Qt event loops. More...

 #include <QMfcApp>

Inherits QApplication.

Public Functions

Static Public Members

Additional Inherited Members


Detailed Description

The QMfcApp class provides merging of the MFC and Qt event loops.

QMfcApp is responsible for driving both the Qt and MFC event loop. It replaces the standard MFC event loop provided by CWinApp::Run(), and is used instead of the QApplication parent class.

To replace the MFC event loop reimplement the CWinApp::Run() function in the CWinApp subclass usually created by the MFC Application Wizard, and use either the static run() function, or an instance of QMfcApp created earlier through the static instance() function or the constructor.

The QMfcApp class also provides a static API pluginInstance() that drives the Qt event loop when loaded into an MFC or Win32 application. This is useful for developing Qt based DLLs or plugins, or if the MFC application's event handling can not be modified.


Member Function Documentation

QMfcApp::~QMfcApp ()

Destroys the QMfcApp object, freeing all allocated resources.

void QMfcApp::enterModalLoop ()   [static]

Inform Qt that a modal loop is about to be entered, and that DeferredDelete events should not be processed. Call this function before calling Win32 or MFC functions that enter a modal event loop (i.e. MessageBox).

This is only required if the Qt UI code hooks into an existing Win32 event loop using QMfcApp::pluginInstance.

See also exitModalLoop().

void QMfcApp::exitModalLoop ()   [static]

Inform Qt that a modal loop has been exited, and that DeferredDelete events should not be processed. Call this function after the blocking Win32 or MFC function (i.e. MessageBox) returned.

This is only required if the Qt UI code hooks into an existing Win32 event loop using QMfcApp::pluginInstance.

See also enterModalLoop().

bool QMfcApp::pluginInstance ( Qt::HANDLE plugin = 0 )   [static]

If there is no global QApplication object (i.e. qApp is null) this function creates a QApplication instance and returns true; otherwise it does nothing and returns false.

The application installs an event filter that drives the Qt event loop while the MFC or Win32 application continues to own the event loop.

Use this static function if the application event loop code can not be easily modified, or when developing a plugin or DLL that will be loaded into an existing Win32 or MFC application. If plugin is non-null then the function loads the respective DLL explicitly to avoid unloading from memory.

 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved)
 {
     if (dwReason == DLL_PROCESS_ATTACH)
         QMfcApp::pluginInstance(hInstance);

     return TRUE;
 }

Set plugin to 0 when calling this function from within the same executable module.

If this function is used, call enterModalLoop and exitModalLoop whenever you call a Win32 or MFC function that opens a local event loop.

 void Dialog::someSlot()
 {
     QMfcApp::enterModalLoop();
     MessageBox(...);
     QMfcApp::exitModalLoop();
 }


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Solutions