Summary : I have a DLL which exports a function. In this function I am calling QApplication::allWidgets() which returns an empty list whereas if this function is in the application returns a list with 19 items.
If I am not mistaken there is a static list of items maintained by the framework. allWidgets() function is returning that list. To my knowledge DLL is supposed to be in the same address space as the application which means I should be able to access all the static variables from DLL. Then why does it make a difference whether the function is in DLL vs application?
Here is DLL code :
------------------------ test.h ----------------
extern "C" TESTSHARED_EXPORT std::string DllFun();
------------------------ test.cpp --------------
std::string DllFun()
{
std::stringstream temp;
QList<QWidget *> list = QApplication::allWidgets();
temp << "Number of widgets from DLL " << list.size();
return temp.str();
}
Here is application code :
------------------------------ mainwindow.cpp ----------------
std::string MainWindow::FunInternal()
{
std::stringstream temp;
QList<QWidget *> list = QApplication::allWidgets();
temp << "Number of widgets from Applicaton " << list.size();
return temp.str();
}
void MainWindow::on_pushButton_clicked()
{
typedef std::string (*FunType)();
HMODULE handle = LoadLibrary(L"Test.dll");
FunType DllFun = (FunType)GetProcAddress(handle, "DllFun");
if (Fun)
{
std::string DllWidgets = DllFun();
std::string InternalWidgets = FunInternal();
ui->textEdit->append(QString(DllWidgets.c_str()));
ui->textEdit->append(QString("\n"));
ui->textEdit->append(QString(InternalWidgets.c_str()));
}
}
When I click the button results are
Number of widgets from DLL 0
Number of widgets from Applicaton 19
I am using Qt 5.2 64 Bit.
Aucun commentaire:
Enregistrer un commentaire