This is a basic example that I need to get to work to use it in my project.
I need someone to help to destroy and rebuild an object on a button click. What I mean is:
//mainwindow.cpp
{//constructor
ui->setupUi(this);
/*private*/frame = new QFrame(ui->centralWidget);
/*private*/temp = new QPushButton(frame);
QPushButton ok = new QPushButton(ui->centralWidget);
ok->setGeometry(100,100,50,50);
connect(ok, SIGNAL(clicked()), SLOT(des()));
}
{//slot des()
temp->~QPuhsButton();
temp = new QPushButton(frame);
}
See, all I need is temp
to be destroyed and rebuilt.
The line temp = new QPushButton(frame);
is not working because with or without it, temp
disappears from the layout, meaning temp->~QPuhsButton();
is working.
Now, the reason this is bothering me is because this works:
{//constructor
ui->setupUi(this);
frame = new QFrame(ui->centralWidget);
temp = new QPushButton(frame);
temp->~QPuhsButton();
temp = new QPushButton(frame);
/*QPushButton ok = new QPushButton(ui->centralWidget);
ok->setGeometry(100,100,50,50);
connect(ok, SIGNAL(clicked()), SLOT(des()));*/
}
I tried this last piece of code to see if it was possible to destroy and rebuild the object the way I was trying to with a button being clicked. Turns out it is, this time temp = new QPushButton(frame);
is working and the button stays there.
EDIT: thanks for the answer and the comment, but I am sorry because I didn´t realize something before asking the question.
The buttons were being deleted/destroyed, they were just not being "repainted" inside the frame when I write temp = new QPushButton(frame);
again, actually they still are not. Help regarding this new problem and again sorry.