Home

Qt based Application Extension

This examples shows how to use the QWinWidget and QMfcApp classes to implement a Qt based user interface in a plugin DLL.

The plugin implements and exports a C function showDialog that can be called by any Windows application to display a modal Qt dialog. Before a Qt based user interface can be created a QApplication object must exist, and the calling application's event loop and the Qt event loop must run together.

 /****************************************************************************
 **
 ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
 **
 ** This file is part of a Qt Solutions component.
 **
 ** Licensees holding a valid Qt Solutions License Agreement may use this
 ** file in accordance with the rights, responsibilities, and obligations
 ** contained therein. Please consult your licensing agreement or contact
 ** sales@trolltech.com if any conditions of this licensing are not clear
 ** to you.
 **
 ** Further information about Qt Solutions licensing is available at:
 ** http://www.trolltech.com/products/qt/addon/solutions/
 ** or by contacting info@trolltech.com.
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/
 #include <qmfcapp.h>
 #include <qwinwidget.h>

 #include <QtGui/QMessageBox>
 #include <windows.h>

 BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
 {
     static bool ownApplication = FALSE;

     if ( dwReason == DLL_PROCESS_ATTACH )
         ownApplication = QMfcApp::pluginInstance( hInstance );
     if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
         delete qApp;

     return TRUE;
 }

The DLL entry point function DllMain uses the QMfcApp::pluginInstance function to make sure that exactly one instance of QApplication exists in the process, and that the DLL owning that instance stays loaded in memory.

 extern "C" __declspec(dllexport) bool showDialog( HWND parent )
 {
     QWinWidget win( parent );
     win.showCentered();
     QMessageBox::about( &win, "About QtMfc", "QtMfc Version 1.0\nCopyright (C) 2003" );

     return TRUE;
 }

The C function showDialog is exported from the DLL and uses the QWinWidget class to provide proper stacking and modality between the native Win32 window and the QMessageBox.


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