PDA

View Full Version : Destructor Link error



Roelof
14th September 2009, 11:04
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

Roelof
14th September 2009, 13:44
IF anyone can help I would greatly appreciate it

Regards

lyuts
14th September 2009, 15:10
...
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.

Roelof
14th September 2009, 15:31
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?

lyuts
14th September 2009, 15:36
Show your code. It is unclear how you call your form.

Roelof
15th September 2009, 09:38
Class Definition:


class Controller : public QWidget
{
Q_OBJECT

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

Class constructor and destructor:


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

Main form:


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

Controller *addressBook = new Controller;
addressBook->show();
return app.exec();
}

Can anybody help?

faldzip
15th September 2009, 10:47
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.

Roelof
15th September 2009, 11:37
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:


Controller::Controller(QWidget *parent): QWidget(parent)
{

QLabel *nameLabel2 = new QLabel(tr("SYSTEM STATE"));
nameLabel2->setFont(QFont("Times", 20, QFont::Bold));

QPalette palette;
palette.setColor(backgroundRole(), QColor(29, 100, 151, 255));
setPalette(palette);

noPowerButton = new QPushButton(tr("&No Power"));
noPowerButton->show();
noPowerButton->setFont(QFont("Times", 16, QFont::Bold));
noPowerButton->setAutoFillBackground(true);

exitButton = new QPushButton(tr("&EXIT"));
exitButton->show();
exitButton->setFont(QFont("Times", 14, QFont::Bold));
exitButton->setAutoFillBackground(true);

connect(noPowerButton, SIGNAL(clicked()), this, SLOT(noPower()));

connect(exitButton,SIGNAL(clicked()),this, SLOT(quit()));

QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(noPowerButton);
buttonLayout1->addStretch();

QGridLayout *mainLayout = new QGridLayout;
mainLayout->addLayout(buttonLayout1, 1, 0);
mainLayout->addLayout(exitButton, 1, 1);

setLayout(mainLayout);
setWindowTitle(tr("Control"));

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);
}

lyuts
15th September 2009, 11:45
The first thing i have noticed is that you don't need to do


noPowerButton->show();
...and...
exitButton->show();


The next thing is what are you doing in your quit() slot?

Roelof
15th September 2009, 14:12
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:


void Controller::quit()
{
system("taskkill /IM PCI_Read.exe");
exit(0);
}

faldzip
15th September 2009, 15:17
maybe use QProcess instead of system()...

nish
16th September 2009, 11:06
Controller *addressBook = new Controller;

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