0

I have a designer form class of some vehicles where constructor holds a index of vehicle:

Vehicle::Vehicle(QWidget *parent, int _index) :
  QDialog(parent),
  ui(new Ui::Vehicle)
{
  this->_index = _index;
}

In main class, I create an object of class:

Vehicle* vehicle = NULL;

and I have a 10 buttons to open a 10 different dialog class of Vehicles:

void MainWindow::OnOpenDialog1()
{
  if(vehicle==NULL)
    vehicle = new vehicle(this, 0);

  if(vehicle->isHidden()) {
    vehicle->show();
  }
  else
    vehicle->hide();
}

void MainWindow::OnOpenDialog2()
{
  if(vehicle==NULL)
    vehicle = new vehicle(this, 1);

  if(vehicle->isHidden()) {
    vehicle->show();
  }
  else
    vehicle->hide();
}
.....

but in this way I open only one dialog, and other buttons opened the same dialog.

Shuld I create a 10 object of class?

Vehicle* vehicle1 = NULL;
Vehicle* vehicle2 = NULL;
Vehicle* vehicle3 = NULL;
....

I thought I could use a single object class and insert only index in the constructor and the data displayed on one changing form depends on index?

demonplus
  • 5,613
  • 12
  • 49
  • 68

0 Answers0