link error with export a class with init in class
-
wrote on 1 Jun 2023, 02:03 last edited by
I have a these code
//a.dll //TableWidget.h #include <QTableWidget> class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget//There is a macro control whether import or export { //... }; //Widget.h #include "TabWidget.h" #include <QTableWidget> #include <QPushButton> class __declspec(dllexport)/*__declspec(dllimport)*/ Widget//There is a macro control whether import or export { public: TableWidget *table = new TableWidget;//OK QPushButton *button = new QPushButton;//OK QTableWidget *t = new QTableWidget//error } //test.exe //main.cpp #include "Widget.h" int main() { }
I got link error LNK2001
LNK2001:unresolved external symbol public: virtual void * __cdecl QTableWidget::scalar deleting destructor'(unsigned int)" (??_GQTableWidget@@UEAAPEAXI@Z) LNK2001:unresolved external symbol "public: virtual void * __cdecl QTableWidget::
vector deleting destructor'(unsigned int)" (??_EQTableWidget@@UEAAPEAXI@Z)
I tried add virtual destructor, delete destructor, add virtual keyword and delete, not work.
VS 2019 16.11.24
Qt version 5.9.2
Any suggestion? -
I have a these code
//a.dll //TableWidget.h #include <QTableWidget> class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget//There is a macro control whether import or export { //... }; //Widget.h #include "TabWidget.h" #include <QTableWidget> #include <QPushButton> class __declspec(dllexport)/*__declspec(dllimport)*/ Widget//There is a macro control whether import or export { public: TableWidget *table = new TableWidget;//OK QPushButton *button = new QPushButton;//OK QTableWidget *t = new QTableWidget//error } //test.exe //main.cpp #include "Widget.h" int main() { }
I got link error LNK2001
LNK2001:unresolved external symbol public: virtual void * __cdecl QTableWidget::scalar deleting destructor'(unsigned int)" (??_GQTableWidget@@UEAAPEAXI@Z) LNK2001:unresolved external symbol "public: virtual void * __cdecl QTableWidget::
vector deleting destructor'(unsigned int)" (??_EQTableWidget@@UEAAPEAXI@Z)
I tried add virtual destructor, delete destructor, add virtual keyword and delete, not work.
VS 2019 16.11.24
Qt version 5.9.2
Any suggestion?@Hu-Junhao said in link error with export a class with init in class:
QTableWidget *t = new QTableWidget//error
Did you copy the code or typed it? Because there is syntax error in this line.
-
I have a these code
//a.dll //TableWidget.h #include <QTableWidget> class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget//There is a macro control whether import or export { //... }; //Widget.h #include "TabWidget.h" #include <QTableWidget> #include <QPushButton> class __declspec(dllexport)/*__declspec(dllimport)*/ Widget//There is a macro control whether import or export { public: TableWidget *table = new TableWidget;//OK QPushButton *button = new QPushButton;//OK QTableWidget *t = new QTableWidget//error } //test.exe //main.cpp #include "Widget.h" int main() { }
I got link error LNK2001
LNK2001:unresolved external symbol public: virtual void * __cdecl QTableWidget::scalar deleting destructor'(unsigned int)" (??_GQTableWidget@@UEAAPEAXI@Z) LNK2001:unresolved external symbol "public: virtual void * __cdecl QTableWidget::
vector deleting destructor'(unsigned int)" (??_EQTableWidget@@UEAAPEAXI@Z)
I tried add virtual destructor, delete destructor, add virtual keyword and delete, not work.
VS 2019 16.11.24
Qt version 5.9.2
Any suggestion?wrote on 1 Jun 2023, 06:01 last edited by JonB 6 Jan 2023, 06:02@Hu-Junhao
As @jsulm has said, this cannot be your real code. Additionally either you don't have#include "TabWidget.h"
or the first extract is not inTableWidget.h
.QTableWidget *t = new QTableWidget//error
Since you have a linker error for an unresolved reference, how do you know that line is the cause of an error? You don't. Your error might just as well come from your
class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget
line. Comment outQTableWidget *t = new QTableWidget//error
to see whether you still get the linker error. -
@Hu-Junhao
As @jsulm has said, this cannot be your real code. Additionally either you don't have#include "TabWidget.h"
or the first extract is not inTableWidget.h
.QTableWidget *t = new QTableWidget//error
Since you have a linker error for an unresolved reference, how do you know that line is the cause of an error? You don't. Your error might just as well come from your
class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget
line. Comment outQTableWidget *t = new QTableWidget//error
to see whether you still get the linker error.wrote on 1 Jun 2023, 07:07 last edited by@JonB @jsulm OKOK real code, fine. That maybe too long
//UICommon.dll //DopingModelWin.h class DS_RED_UICOMMON_EXPORT DopingModelWin : public BaseWindow { Q_OBJECT public: /// @brief explicit DopingModelWin(QWidget* parent = nullptr); static DopingModelWin* GetInstance(QWidget* parent = nullptr) { static DopingModelWin* d = new DopingModelWin(parent); return d; } QGroupBox* creatGroup(QString title); void msg_windows_change(int sunId, QString& value); void refreshUIById(int Id); void resetUIData(); std::string getUIJsonDataById(int Id); void setUIJsonData(DSR_Json_Tool* pData, int Id); void undo_or_redo_action(HISTROYACTION action, int dataId, QVariant& data); void add_data_to_doping_fixed(QString region, QString dopants, double concentration); void add_data_to_doping_gauss(QString baseline, double distance, QString dopants, double concentration, double junction_depth, double junction_concentration); void modify_doping_fixed(int row, int column, QString data); void modify_doping_gauss(int row, int column, QString data); void remove_doping_fixed_row(int row); void remove_doping_gauss_row(int row); protected: bool isValidFixedTable(QString region); bool isValidGaussTable(QString edge, QString name); bool checkInputData(); private: void SetUpUI(); void initConnect(); void initGaussTable(); enum { col_baseLine, col_distoLine , col_dopants, col_concentration, col_junctionDepth, col_junctionCon,col_count }; private: LockerButton* m_FixedButton; LockerButton* m_GaussiaButton; QWidget* m_FixedWidget; QWidget* m_GaussiaWidget; MultiSelectComboBox* m_fixedCombox; MultiSelectComboBox* m_gaussianCombox; DSRComboBox* m_donorbox; // DSRComboBox* m_acceptbox; DSRComboBox* m_donorbox1; DSRLineEdit* m_pdonorTxt; // DSRLineEdit* m_pacceptTxt; DSRLineEdit* m_pconTxt; DSRLineEdit* m_pDepthTxt; DSRLineEdit* m_pJunTxt; DSRLineEdit* m_pDistanceTxt; DSRTableWidget* m_fixedTable; DSRTableWidget* m_gaussianTable; QStringList m_interface; QStringList m_metal; QPushButton* m_pGaussianBtn; QPushButton* pFixedBtn1; DSRComobDelegate m_MaterialeNames; LockerButton *import_lockerbutton; QWidget *import_widget; QGridLayout *import_layout; QLabel *import_contact_label; QLabel *import_material_label; QLabel *import_filename_label; QComboBox *import_contact_combobox; QComboBox *import_material_combobox; QPushButton *import_filename_button; DSRTableWidget *import_doping_tablewidget = new DSRTableWidget;//strange, link error too, different from first code QTableWidget *import_doping_tablewidget1 = new QTableWidget;//link error QPushButton *import_build_button; }; //DSRTableWidget.h class DS_RED_UICOMMON_EXPORT DSRTableWidget :public QTableWidget { Q_OBJECT public: DSRTableWidget(QWidget* parent = Q_NULLPTR); DSRTableWidget(int rows, int columns, QWidget* parent = Q_NULLPTR); ~DSRTableWidget(); void setText(int nRow, int nCol, QString text); void setText(int nRow, int nCol, std::string text); void setText(int nRow, int nCol, double dtext); QString getText(int nRow, int nCol); QString getData(int nRow, int nCol); /** * @brief when you haven't set the value of col,it means all column. * @param b isEditable * @param col column num */ void setColumnEditable(bool b,int col = -1); void setColumnNumberFiter(int col); void removeCurrentItem(); void initConnect(); void setValidInsert(bool isOpen) { isValidInsert = isOpen; } void setAutoAdjustColumWidth(bool b) { m_bAutoAdjust = b; }; void installParameter(); protected: void mousePressEvent(QMouseEvent* event); void mouseDoubleClickEvent(QMouseEvent* event); void contextMenuEvent(QContextMenuEvent* event); void resizeEvent(QResizeEvent* event); void keyPressEvent(QKeyEvent* event); Q_SIGNALS: void rowRemoved(int row); void rowInserted(int row); private: bool isValidInsert; QTableWidgetItem* m_CurrentItem; QMap<int, bool> m_ColEditStatus; QMap<int, bool> m_colOnlyNumber; QRegExpValidator* m_validator; bool m_bAutoAdjust; bool m_bInstallParameter; }; //main.exe //test.cpp #include "DopingModelWin.h"//link error test.obj
-
I have a these code
//a.dll //TableWidget.h #include <QTableWidget> class __declspec(dllexport)/*__declspec(dllimport)*/ TableWidget : public QTableWidget//There is a macro control whether import or export { //... }; //Widget.h #include "TabWidget.h" #include <QTableWidget> #include <QPushButton> class __declspec(dllexport)/*__declspec(dllimport)*/ Widget//There is a macro control whether import or export { public: TableWidget *table = new TableWidget;//OK QPushButton *button = new QPushButton;//OK QTableWidget *t = new QTableWidget//error } //test.exe //main.cpp #include "Widget.h" int main() { }
I got link error LNK2001
LNK2001:unresolved external symbol public: virtual void * __cdecl QTableWidget::scalar deleting destructor'(unsigned int)" (??_GQTableWidget@@UEAAPEAXI@Z) LNK2001:unresolved external symbol "public: virtual void * __cdecl QTableWidget::
vector deleting destructor'(unsigned int)" (??_EQTableWidget@@UEAAPEAXI@Z)
I tried add virtual destructor, delete destructor, add virtual keyword and delete, not work.
VS 2019 16.11.24
Qt version 5.9.2
Any suggestion?wrote on 1 Jun 2023, 07:21 last edited by@Hu-Junhao said in link error with export a class with init in class:
scalar deleting destructor
Start by getting rid of your
~DSRTableWidget();
declaration inDSRTableWidget.h
since you don't seem to define that destructor? -
@Hu-Junhao said in link error with export a class with init in class:
scalar deleting destructor
Start by getting rid of your
~DSRTableWidget();
declaration inDSRTableWidget.h
since you don't seem to define that destructor? -
@JonB I define it in cpp as empty function body. My current solution is put initialization in cpp instead of in class body. But what puzzles me is QPushButton and other QWidget is good.
1/7