如何将菜单点击与 Qt Creator 中的动作连接起来? [英] How to connect menu click with action in Qt Creator?

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

问题描述

我对 Qt 完全陌生.

I am completely new to 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 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天全站免登陆