| Home | ![]() |
The QMfcApp class provides merging of the MFC and Qt event loops. More...
#include <qmfcapp.h>
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 for Qt based DLLs loaded into an MFC or Win32 application.
Use the static function instance() to automatically use the command line passed to the CWinApp.
QMfcApp *qtApp;
BOOL MyMfcApp::InitInstance()
{
// standard MFC initialization
int argc = ...
char **argv = ...
qtApp = new QMfcApp( this, argc, argv );
// Qt GUI initialization
}
BOOL MyMfcApp::Run()
{
int result = qtApp->exec();
delete qtApp;
qtApp = 0;
return result;
}
See also instance() and run().
Use this static function if you want to perform additional initializations after creating the application object, or if you want to create Qt GUI elements in the InitInstance() reimplementation of CWinApp:
BOOL MyMfcApp::InitInstance()
{
// standard MFC initialization
// ...
// This sets the global qApp pointer
QMfcApp::instance( this );
// Qt GUI initialization
}
BOOL MyMfcApp::Run()
{
int result = QMfcApp::run( this );
delete qApp;
return result;
}
See also run().
Example: step4/qtmfc.cpp.
The application installs an event filter that drives the Qt event loop in a Qt based DLL plugin that is being loaded into MFC or Win32 applications. If plugin is non-null the function loads the DLL explicitly to avoid unloading from memory.
Use this static function in your plugin initialization code, e.g. in an implementation of the DllMain entry point function:
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved )
{
if ( dwReason == DLL_PROCESS_ATTACH )
QMfcApp::pluginInstance( hInstance );
return TRUE;
}
Example: qtdll/main.cpp.
Calling this static function in a reimplementation of CWinApp::Run() is the simpliest way to use the QMfcApp class:
int MyMfcApp::Run()
{
return QMfcApp::run( this );
}
Since a QApplication object must exist before Qt widgets can be created you cannot use this function if you want to use Qt-based user interface elements in, for example, the InitInstance() function of CWinApp. In such cases, create an instance of QApplication explicitly using instance() or the constructor.
See also instance().
Example: step4/qtmfc.cpp.
This file is part of the Qt Solutions.
Copyright © 2003-2005
Trolltech. All Rights Reserved.
| Copyright © 2003-2005 Trolltech | Trademarks | Qt Solutions
|