PDA

View Full Version : modeless dialog in qt dll loaded in existing non qt app



elizabeth.h1
28th July 2009, 10:36
Hello

I am using
- Qt 4.5 opensource
- Qt/Mfc migration Framework. (open source edition)

I want to make qt gui dll that will be loaded in non qt existing application for which I don't have source code.

the code for the dll :


#include <qmfcapp.h>
#include <qwinwidget.h>

#include <QtGui/QMessageBox>
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID )
{
static bool ownApplication = FALSE;
if ( dwReason == DLL_PROCESS_ATTACH )
ownApplication = QMfcApp::pluginInstance( hInstance );
if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
delete qApp;
return TRUE;
}

void showqt(HWND parent)
{
QWinWidget* win=new QWinWidget( parent );
win->showCentered();
Ui::GoToCellDialog ui;
QDialog *dialog = new QDialog(win);
ui.setupUi(dialog);
dialog->show();
return ;
}

The problem is that the dialog is not shown at all, or sometimes it
is shown and very quickly disappears . Note that when I am trying to use modal dialog (dialog->exec()) the dialog is shown .
Maybe that is cause modal dialog has its own message loop,
but i was expecting this will work cause I am merging the application loop with the qt loop with QMfcApp:: pluginInstance.

Form the documentation :
"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."

Thanks

wysota
28th July 2009, 11:25
You are creating your objects on stack and they go out of scope when you leave the function and are destroyed. Create the ui object on heap instead or make a proper QDialog subclass with embedded ui object and instantiate the dialog on heap.

elizabeth.h1
28th July 2009, 13:49
Thank you. It works