如何在Qt Creator中将菜单单击与动作联系起来? [英] How to connect menu click with action in Qt Creator?

查看:631
本文介绍了如何在Qt Creator中将菜单单击与动作联系起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Qt完全陌生.

我从一个新的Qt4 GUI应用程序开始.

I started with a new Qt4 GUI Application.

使用设计器,我创建了一个像这样的菜单:

Using the designer, I have created a menu like so:

File
 - Exit

如何获得与菜单项相关联的动作?

How do I get an action associated with the menu item?

我找到了一个叫做信号和插槽编辑器"的东西,但不知道如何使用它.

I found something called the 'Signals and slots editor' but have no idea how to use it.

推荐答案

选择信号插槽编辑器后,单击绿色加号.它会为您提供4个字段来填写.对于发送方,您可以选择创建信号的方式.例如,ActionExit可能是您为退出菜单项创建的名称.该信号可能会被click().接收器通常是您创建的具有所有方法的类.插槽是您要在该类中创建的要执行的方法.例如:

Click on the green plus sign after you selected the signals Slots Editor. It will give you 4 fields to fill in. For sender you select what is creating the signal. For example ActionExit might be the name you created for the exit menu item. The signal is probably going to be clicked(). The receiver is usually the class that you created that has all of your methods. The slot is the method you created in that class that you want to execute. For example:

actionExit clicked() <nameOfClass> exitGame()

希望这会有所帮助.

这篇关于如何在Qt Creator中将菜单单击与动作联系起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆