csrss.exe
当我向//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()......
}
添加MyWidget
时,应用程序崩溃了代码tabWidget
。
我设置了255
,LIBS
,INCLUDEPATH
,它们似乎没问题。
所以我想知道,我如何正确地将共享库中的小部件嵌入DEPENDPATH
?谢谢!
答案 0 :(得分:0)
由于您使用了以下演员资格,您有未定义的行为......
MyWidget *widget = (MyWidget*)myLib.resolve("getMyWidget");
getMyWidget
的正确类型是......
MyWidget *(*)()
您需要解析符号,然后调用它...
typedef MyWidget *(*get_my_widget_type)();
if (get_my_widget_type get_my_widget = get_my_widget_type(myLib.resolve("getMyWidget"))) {
MyWidget *widget = get_my_widget();
tabWidget->addTab(widget, "MyWidget");
}