-1

I want to code a function to show the basic flow of my GUI like if I call that function in a slot it start transitions in states as FileMenu->Open(signal triggered and enables the slot connected to it) and so on. I tried with state machine as:

d1->assignProperty(ui->menuFile,"visible",true);

d0->addTransition(d1);

d1->addTransition(ui->actionOpen,SIGNAL(triggered()),d0);

dem->addState(d0);
dem->addState(d1);

dem->setInitialState(d0);
dem->start();  

File menu is not appearing at the place. Also Signal is not triggered on state transition. I am new to QStateMachine. I am not sure about triggering a signal this way is possible or not. If yes then and what is wrong in my code or is there any better way to do this?


Edit: file menu correction :

QRect r0 =  this->geometry();
QRect tbar = ui->menuBar->geometry();
QRect r = ui->menuFile->geometry();
r.setCoords(r0.x(),r0.y()+tbar.height(),r0.x()+r.width(),r0.y()+r.height()+tbar.height());

ui->menuFile->setGeometry(r);
ui->menuFile->show();
Tab
  • 785
  • 2
  • 11
  • 27

1 Answers1

0

You say that the code given in the question is within a function, and you want the function to start transitions to show the menu. The function itself is called within a slot.

It is not correct to re-create the state machine in this function, nor is it really necessary for the function to exist.

You should:

  1. Create the state machine in the widget/object constructor, and do it only once.

  2. Add a QSignalTransition to trigger transition to d1.

You should also verify that the code otherwise works. Instead of having a state machine in your function, simply show the menu using ui->menuFile->show(). This must work before you attempt anything else.

You said that your function is called from a slot. Obviously there's a signal somewhere that triggers that slot. That's the object and the signal that you use to create a QSignalTransition.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313