如何使用 Qt Creator 将按钮单击信号(“触发”信号)与工具栏中用户按钮的操作/槽函数连接起来?
已经看到“stackoverflow”论坛上关于在正在设计的应用程序下设计和管理菜单和操作的早期现有讨论。在 Qt Creator 下开发(请参阅“如何在 Qt Creator 中连接菜单点击与操作?”:如何在 Qt Creator 中将菜单点击与操作连接起来?),恐怕我对我正在尝试的工具栏中的操作按钮也有同样的问题创造&填充 Qt 创建者...
那么,让我们开始吧!
(1) 我在动作编辑器中创建至少一个动作... (2) 我将该操作拖放到工具栏上
(步骤 1 和 2 都可以,这些步骤没有困难,尽管这对我来说是一种非常不常见的执行此类操作的方法,因为其他 UIM 设计工具通常会提出相反的步骤2 和 1 做同样的事情,在我看来这更“自然”,但是,我知道,在我们的软件设计和编程世界中,有很多东西存在并共存......)
=> ; (3)如何关联(连接)单击给定的工具栏按钮时应该调用的函数(我要实现的)?
我的意思是,如何连接“触发”信号将操作(工具栏按钮)指定给稍后要实现的所需插槽(功能)...?是否可以使用 Qt Creator 中的“信号和槽编辑器”执行此类操作,或者我是否必须在代码中的某个位置自己调用“connect()”才能实现此目的?非常感谢此时为完美初学者提供的任何帮助/建议/详细示例...
事实上,我想知道是否可以自己不调用 connect() 来满足这种需要,以及 Qt Creator 是否会创建插槽(函数)原型本身,还是我们必须自己创建这样的槽(函数)原型,然后 Qt Creator 才能考虑新的槽(函数)原型并在这个通常/正常的 UIM 设计步骤中真正帮助/帮助用户/开发人员/ 设计能力... ?
此致。
阿兰-皮埃尔
Having seen earlier existing discussion on "stackoverflow" forum about designing and managing menus and actions under an application being designed & developped under Qt Creator (see "How to connect menu click with action in Qt Creator?" : How to connect menu click with action in Qt Creator?), I'm afraid I have same questions about action buttons in a toolbar I'm trying to create & populate with Qt creator...
So, let's go !
(1) I create at least one action in the Action Editor...
(2) I drag&drop that action to the toolbar
(steps 1 & 2 are ok, no difficulties with these ones, although it is a quite unusal way of doing such things for me, because other UIM designing tools usually propose inverse steps 2 & 1 to do the same, which is more "natural" in my opinion, but, I know, many many things exist and co-exist in our world of software designing & programming...)
=> (3) How to associate (connect) the function (which I'm going to implement) that is supposed to be called when clicking the given toolbar button ?
I mean, how to connect the "triggered" signal for the given action (toolbar button) to the desired slot (function) to be implementing later... ? Is it possible to do such things with the "Signals and slots editor" inside Qt Creator, or do I have to call "connect()" by myself somewhere in the code to achieve this ? Many thanks in advance for any help/suggestion/detailed example for perfect beginner at this point...
In fact, I would to know wether it is possible not to call connect() by myself for such need and wether Qt Creator will create slot (function) prototype by itself or do we have to create such slot (function) prototypes by ourselves before Qt Creator can take the new slot (function) prototype into account and really assist/help user/developper in this usual/normal UIM design step / designing capability... ?
Best regards.
Alain-Pierre
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
QAction
是您的窗口的成员,那么正常的...将使用适当命名的槽方法连接操作的
trigger
信号。这通常由使用设计器创建的 GUI 类自动调用。因此,例如,如果操作名为actionSomething
,则在 GUI 类中使用如下签名创建一个插槽:...将意味着您不必手动
连接
信号和槽。此外,在操作编辑器中右键单击操作并选择“转到槽...”将允许您为该操作可能发出的任何信号创建槽函数。
If the
QAction
is a member if your window, then the normal...will connect an action's
trigger
signal with an appropriately named slot method. This is normally called automatically by GUI classes created using the designer. So if the action is namedactionSomething
for example, creating a slot in your GUI class with a signature like:...will mean that you don't have to manually
connect
the signals and slots.Also, right-clicking on the action in the action editor and selecting 'Go to slot...' will allow you to create a slot function for any signal that the action may emit.