Results 1 to 12 of 12

Thread: Destructor Link error

  1. #1
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Destructor Link error

    Good day.

    I am having trouble exiting my program when executed. It doesn't free up the memory space and the program keeps running after closing it.
    I figured I should create the destuctor in order to close the program properly.

    My class looks as follows:

    class Controller : public QWidget
    {
    Q_OBJECT

    public:
    Controller(QWidget *parent = 0);
    ~Controller();


    And implementation is as follows:

    Controller::Controller(QWidget *parent): QWidget(parent)
    { .... }
    Controller::~Controller()
    {...}

    I get the following error:

    error LNK2019: unresolved external symbol "public: virtual __thiscall Controller::~Controller(void)" (??1Controller@@UAE@XZ) referenced in function "public: virtual void * __thiscall Controller::`scalar deleting destructor'(unsigned int)" (??_GController@@UAEPAXI@Z) in controller.obj

    If anybody has any ideas. Please help or tell met how to ensure that the program closes completely.

    Thanx in advance

  2. #2
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Destructor Link error

    IF anyone can help I would greatly appreciate it

    Regards

  3. #3
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Destructor Link error

    Quote Originally Posted by Roelof View Post
    ...
    I figured I should create the destuctor in order to close the program properly.
    ...
    If you don't create the destructor, the compiler will create the default one for you.

    Try to rerun qmake and make.
    I'm a rebel in the S.D.G.

  4. #4
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Destructor Link error

    The program doesn't close completely on exit.

    Therefore the idea arose to create a destructor.

    However, I receive the error.

    I don't think the major task of rerunning qmake and nmake is neccesarry to figure this out.

    If anybody else hav an idea please help.

    Just some background on the project:
    QT4.5 in visual studio 2005. Windows XP

    My program creates a few buttons that sends data over a PCI card.
    I created an exit/quit button, but the program doesn't seem to close completely on this command. The form dissapears but the program is still running in my task manager.
    How do I close this completely? Can this be done by creating a destructor?

  5. #5
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Destructor Link error

    Show your code. It is unclear how you call your form.
    I'm a rebel in the S.D.G.

  6. #6
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Destructor Link error

    Class Definition:

    Qt Code:
    1. class Controller : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Controller(QWidget *parent = 0);
    7. ~Controller();
    To copy to clipboard, switch view to plain text mode 

    Class constructor and destructor:

    Qt Code:
    1. Controller::Controller(QWidget *parent): QWidget(parent)
    2. {...}
    3. Controller::~Controller()
    4. {...}
    To copy to clipboard, switch view to plain text mode 
    Main form:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. Controller *addressBook = new Controller;
    6. addressBook->show();
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Can anybody help?
    Last edited by wysota; 15th September 2009 at 11:00.

  7. #7
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Destructor Link error

    use CODE tags when pasting code.

    And I can't see any close/quit button in your code. What you have pasted is rather not useful. Try showing us more code to get some idea how do you close your app, what do you do in constructor etc. because there is the cause of your problem.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  8. #8
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Destructor Link error

    Hi. I'm sorry for not adding the code quotes.

    I receive the error when I compile the program. So there is a problem with the declaration of my destructor.
    My constuctor is rather long. However I pasted it but left out some duplicate buttons. This is the core of my constuctor. hope this help:

    Qt Code:
    1. Controller::Controller(QWidget *parent): QWidget(parent)
    2. {
    3.  
    4. QLabel *nameLabel2 = new QLabel(tr("SYSTEM STATE"));
    5. nameLabel2->setFont(QFont("Times", 20, QFont::Bold));
    6.  
    7. QPalette palette;
    8. palette.setColor(backgroundRole(), QColor(29, 100, 151, 255));
    9. setPalette(palette);
    10.  
    11. noPowerButton = new QPushButton(tr("&No Power"));
    12. noPowerButton->show();
    13. noPowerButton->setFont(QFont("Times", 16, QFont::Bold));
    14. noPowerButton->setAutoFillBackground(true);
    15.  
    16. exitButton = new QPushButton(tr("&EXIT"));
    17. exitButton->show();
    18. exitButton->setFont(QFont("Times", 14, QFont::Bold));
    19. exitButton->setAutoFillBackground(true);
    20.  
    21. connect(noPowerButton, SIGNAL(clicked()), this, SLOT(noPower()));
    22.  
    23. connect(exitButton,SIGNAL(clicked()),this, SLOT(quit()));
    24.  
    25. QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(noPowerButton);
    26. buttonLayout1->addStretch();
    27.  
    28. QGridLayout *mainLayout = new QGridLayout;
    29. mainLayout->addLayout(buttonLayout1, 1, 0);
    30. mainLayout->addLayout(exitButton, 1, 1);
    31.  
    32. setLayout(mainLayout);
    33. setWindowTitle(tr("Control"));
    34.  
    35. ShellExecute(NULL, L"open", L"C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\Projects\\PCI_Read\\AMB_3\\bin\\PCI_Read.exe", NULL, NULL, SW_SHOWNORMAL);
    36. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Destructor Link error

    The first thing i have noticed is that you don't need to do
    Qt Code:
    1. noPowerButton->show();
    2. ...and...
    3. exitButton->show();
    To copy to clipboard, switch view to plain text mode 

    The next thing is what are you doing in your quit() slot?
    I'm a rebel in the S.D.G.

  10. #10
    Join Date
    Aug 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Destructor Link error

    Hi. Thanx for all your help so far.

    I realized that the when I run the program in visual studio it doesn't close completely, but when I run the .exe file that was created by visual studio it closes.
    I realize this is more a Visual studio question now, so I will close this discussion.

    I just want to include my quit() slot:

    Qt Code:
    1. void Controller::quit()
    2. {
    3. system("taskkill /IM PCI_Read.exe");
    4. exit(0);
    5. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Destructor Link error

    maybe use QProcess instead of system()...
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  12. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Destructor Link error

    Controller *addressBook = new Controller;

    try to make this object on stack instead of heap and see it the program closes

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  5. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.