|  | Home

# QMfcApp Class Reference

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

     #include <QMfcApp>

Inherits QApplication.

- List of all members, including inherited members

## Public Functions

| ~QMfcApp ()

## Reimplemented Public Functions

virtual bool | winEventFilter ( MSG * msg, long * result )

- 16 public functions inherited from QApplication
- 4 public functions inherited from QCoreApplication
- 29 public functions inherited from QObject

## Static Public Members

void | enterModalLoop ()
void | exitModalLoop ()
bool | pluginInstance ( Qt::HANDLE plugin = 0 )

- 73 static public members inherited from QApplication
- 38 static public members inherited from QCoreApplication
- 4 static public members inherited from QObject

### Additional Inherited Members

- 13 properties inherited from QApplication
- 4 properties inherited from QCoreApplication
- 1 property inherited from QObject
- 7 public slots inherited from QApplication
- 1 public slot inherited from QCoreApplication
- 1 public slot inherited from QObject
- 5 signals inherited from QApplication
- 1 signal inherited from QCoreApplication
- 1 signal inherited from QObject
- 1 public type inherited from QObject
- 1 protected function inherited from QApplication
- 1 protected function inherited from QCoreApplication
- 7 protected functions inherited from QObject
- 2 protected variables inherited from QObject

## 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();
     }

### bool QMfcApp::winEventFilter ( MSG * msg, long * result ) `[virtual]`

Reimplemented from QCoreApplication::winEventFilter().