using namespace std;
...
vector<QPushButton*> oListButton;
...
private slots:
void oTest();
using namespace std;
...
vector<QPushButton*> oListButton;
...
private slots:
void oTest();
To copy to clipboard, switch view to plain text mode
void frmMain::on_btnExtraButton_clicked()
{
oListButton.insert(oListButton.end(), buttonA); // use a normal std::vector to store the button, so I can later check which button was pressed
int iXlocation = 50;
int iYlocation = 50;
int iHeight = 100;
int iWidth = 100;
buttonA->setGeometry(iXlocation , iYlocation , iHeight , iWidth ); // coordinate (0,0) is in the left upper corner. Maybe i switched height en width, you'll find out soon enough
buttonA->show(); // so you can actually see it
QObject::connect(oListButton
[oListButton.
size() - 1],
SIGNAL(clicked
()),
this,
SLOT(oTest
()));
//add the last button in the vector to a connect (just so something happened when it got pressed) }
void frmMain::on_btnRemoveAll_clicked()
{
for (int a = 0; oListButton.size() > a; a++)
{
QObject::disconnect(oListButton
[a
],
SIGNAL(clicked
()),
this,
SLOT(oTest
()));
oListButton[a]->hide();
oListButton[a]->deleteLater();
}
oListButton.clear();
}
void frmMain::oTest()
{
QObject* obj
= sender
();
//obj is now the object of the sender, which i will find in my vector with a for-loop int iTest = -1;
for (int a = 0; oListButton.size() > a; a++)
{
if (oListButton[a] == sender())
{
iTest = a;
}
}
}
void frmMain::on_btnExtraButton_clicked()
{
QPushButton *buttonA = new QPushButton(this); //create new button, with this as parent
oListButton.insert(oListButton.end(), buttonA); // use a normal std::vector to store the button, so I can later check which button was pressed
int iXlocation = 50;
int iYlocation = 50;
int iHeight = 100;
int iWidth = 100;
buttonA->setGeometry(iXlocation , iYlocation , iHeight , iWidth ); // coordinate (0,0) is in the left upper corner. Maybe i switched height en width, you'll find out soon enough
buttonA->show(); // so you can actually see it
QObject::connect(oListButton[oListButton.size() - 1], SIGNAL(clicked()), this, SLOT(oTest())); //add the last button in the vector to a connect (just so something happened when it got pressed)
}
void frmMain::on_btnRemoveAll_clicked()
{
for (int a = 0; oListButton.size() > a; a++)
{
QObject::disconnect(oListButton[a], SIGNAL(clicked()), this, SLOT(oTest()));
oListButton[a]->hide();
oListButton[a]->deleteLater();
}
oListButton.clear();
}
void frmMain::oTest()
{
QObject* obj = sender(); //obj is now the object of the sender, which i will find in my vector with a for-loop
int iTest = -1;
for (int a = 0; oListButton.size() > a; a++)
{
if (oListButton[a] == sender())
{
iTest = a;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks