//the subclass of widget in shared library
class MYWIDGETSHARED_EXPORT MyWidget : public QWidget
{
Q_OBJECT
public:
MyWidget(QWidget *parent = 0);
void do_something();
};
extern "C"{
MYWIDGETSHARED_EXPORT MyWidget *getMyWidget(){ return new MyWidget;}
}
//the application which will use the shared library
void MainWindow::creatCentralWidget()
{
QTabWidget *tabWidget = new QTabWidget(this);
QLibrary myLib("xxx/MyWidget.dll");
if(myLib.load()){
MyWidget *widget = (MyWidget*)myLib.resolve("getMyWidget");
tabWidget->addTab(widget,"MyWidget");//Here cause crash!
}
//.......do_something()......
}
When I add MyWidget
to tabWidget
, the application crashed with code 255
.
I have set the LIBS
, INCLUDEPATH
, DEPENDPATH
, it seems no problem with them.
So I want to know, how can I correctly embed the widget from a shared library into QTabWidget
? Thank you!