PDA

View Full Version : Problem about using Designer to create menu,add action and slot?



sharkmouse
15th January 2010, 16:26
hello,
i am a newer of qt,and use designer,i found i can add some menu and sub menu of the mainwindow,can add a action to each menu item and a slot of the action,but i does not work,what is the matter?
  i use the vs 2008 with qt integration plugin.i created a new project of qt application. i add a menu item called 'SYSTEM,the objectname is :menuSYSTEM,then the plugin can create the code below:
  menuSYSTEM = new QMenu(menuBar);
menuSYSTEM->setObjectName(QString::fromUtf8("menuSYSTEM"));
  
after that ,i add a new action,and the Text property of the action is 'SYSTEM'。the code is:
  actionSysterm = new QAction(MainWindow);
actionSysterm->setObjectName(QString::fromUtf8("actionSysterm")) ;
menuBar->addAction(menuSYSTEM->menuAction());
  
now i add a slot which the sender is the action:
  QObject::connect(actionSystem,SIGNAL(trigg ered() ),MainWindow,SLOT(close());

after i compile the code,i does not work。so i tried to modify the code of 'ui_Mainwindow.h'
change menuBar->addAction(menuSYSTEM->menuAction());
to
menuBar->addAction(actionSystem);
now it works.
what is the matter?whether my procedure is right?
i think that modify the ui_xxx.h is not a normal ,is that right?who can tell me how to do it?
thanks.
  

wysota
22nd January 2010, 11:22
i am a newer of qt,and use designer,i found i can add some menu and sub menu of the mainwindow,can add a action to each menu item and a slot of the action,but i does not work,what is the matter?
What does not work?

It seems you menuSYSTEM is a menu and not an action. You probably added a submenu to your SYSTEM action (which caused it to be transformed into a menu) and then deleted it (but the menu was not converted back into an action automatically). Go back to Designer, delete the menu entry and create it again.