I load my qt-dll by button clicking:
void CMFCTestDlg::OnBnClickedButton1()
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("qttest.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "createWindow");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
char * params[] = {"1"};
(ProcAdd) (1, params);
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
MessageBox(L"Message printed from executable\n");
}
void CMFCTestDlg::OnBnClickedButton1()
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("qttest.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "createWindow");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
char * params[] = {"1"};
(ProcAdd) (1, params);
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
MessageBox(L"Message printed from executable\n");
}
To copy to clipboard, switch view to plain text mode
Function createWindow() is as follows:
extern "C" __declspec(dllexport) int createWindow(int argc, char *argv[])
{
Q_CHECK_PTR( qApp );
MainWindow* w = MainWindow::getInstance();
qApp->setMainWidget(w);
w->show();
return qApp->exec();
}
extern "C" __declspec(dllexport) int createWindow(int argc, char *argv[])
{
new QApplication(argc, argv);
Q_CHECK_PTR( qApp );
MainWindow* w = MainWindow::getInstance();
qApp->setMainWidget(w);
w->show();
return qApp->exec();
}
To copy to clipboard, switch view to plain text mode
When I click button then MainWindow appears, I close that window and then I click button again -- raising up assert: qcoreapplication: there should be only one application object...
Then I wrote the following code:
{
qApp->exit();
delete qApp;
}
void MainWindow::closeEvent(QCloseEvent * event)
{
qApp->exit();
delete qApp;
}
To copy to clipboard, switch view to plain text mode
But now i'm getting error in _CrtIsValidHeapPointer method after second closing of MainWindow.
How to unload qt-dll correctly?
Bookmarks