I have the following Dll, which should show a single QWidget:
file testqtlib.h
#pragma once
#include <QtCore/qglobal.h>
#if defined(TESTQTLIB_LIBRARY)
# define TESTQTLIB_EXPORT Q_DECL_EXPORT
#else
# define TESTQTLIB_EXPORT Q_DECL_IMPORT
#endif
extern "C" TESTQTLIB_EXPORT void createWidget();
file testqtlib.cpp
#include <QtWidgets>
#include "testqtlib.h"
void createWidget() {
auto widget = new QWidget;
widget->resize(100, 100);
widget->move(0, 0);
widget->show();
}
I try to call the createWidget() function from another Qt-program, which originally does not contain gui and widgets in its .pro-file:
QLibrary library("testQtLib.dll");
library.load();
typedef void (*testWidget)(void);
auto crW = (testWidget)library.resolve("createWidget");
if (crW) {
debugFile << __func__ << "crW OK:" << std::endl;
crW();
} else
debugFile << __func__ << "crW empty" << std::endl;
debugFile shows that crW was true (non-zero), but the calling program crashs at the call crW(). What is the reason?
Qt5Gui.dll and Qt5Widgets.dll are available in the system path. If I try the same call from the program, which contains gui and widgets in its .pro-file, everything works fine.
Should I load somehow Qt5Gui.dll and Qt5Widgets.dll or what can be a solution?