Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. link error with export a class with init in class
Forum Updated to NodeBB v4.3 + New Features

link error with export a class with init in class

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 681 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hu Junhao
    wrote on last edited by
    #1

    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?

    jsulmJ JonBJ 3 Replies Last reply
    0
    • H Hu Junhao

      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?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • H Hu Junhao

        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?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @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 in TableWidget.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 out QTableWidget *t = new QTableWidget//error to see whether you still get the linker error.

        H 1 Reply Last reply
        0
        • JonBJ JonB

          @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 in TableWidget.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 out QTableWidget *t = new QTableWidget//error to see whether you still get the linker error.

          H Offline
          H Offline
          Hu Junhao
          wrote on last edited by
          #4

          @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
          
          1 Reply Last reply
          0
          • H Hu Junhao

            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?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @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 in DSRTableWidget.h since you don't seem to define that destructor?

            H 1 Reply Last reply
            0
            • JonBJ JonB

              @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 in DSRTableWidget.h since you don't seem to define that destructor?

              H Offline
              H Offline
              Hu Junhao
              wrote on last edited by
              #6

              @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.

              H 1 Reply Last reply
              0
              • H Hu Junhao

                @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.

                H Offline
                H Offline
                Hu Junhao
                wrote on last edited by
                #7

                @jsulm Could you give me some advice?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved