是否可以将模型对象的插槽连接到 QT4 -Designer 中的 GUI?

发布于 2024-09-05 18:12:17 字数 532 浏览 4 评论 0原文

所以我尝试使用 QTDesigner 和 C++ 构建模型视图窗口。

因此,我创建了一个 QOBject 派生类作为我的模型。它提供了插槽和信号来访问它,例如:setFileName(QString) 或 fileNameChanged(QString)。

我开始在 QTDesigner 中使用信号拖放,发现它非常 VA-Smalltalk-Like 很好。过了一会儿,我想知道是否也可以将我的模型连接到此。那么是否有可能以某种方式将我的模型对象引入到 Window/GUI 中,并让 QTDesigner 将信号和槽从模型对象连接到 GUI。

本质上:为我写:

connect( model, SIGNAL(fileNameChanged(QString)), ui->labelFn, SLOT(setText(QString)))
connect( ui-textEdit2, SIGNAL(textChanged(QString)), model, SLOT(setFileName(QString)))

谢谢你的解释

So I try to build a Model-View window using QTDesigner and C++.

For that reason I created a QOBject derived class as my model. It provides slots and signals to access it like: setFileName(QString) or fileNameChanged(QString).

I got a little into using signal drag and drop in QTDesigner and found it quite VA-Smalltalk-Like nice. After a while I was wondering if I could also connect my model to this. So is it possible to somehow introduce my model object into the Window/GUI and let QTDesigner connect signals and slots from the model object to the GUI.

In essence: Write for me:

connect( model, SIGNAL(fileNameChanged(QString)), ui->labelFn, SLOT(setText(QString)))
connect( ui-textEdit2, SIGNAL(textChanged(QString)), model, SLOT(setFileName(QString)))

Thanks for explaining

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夢归不見 2024-09-12 18:12:17

正如 jopa 所说,如果您想在设计器中执行此操作,则需要让设计器了解您的组件,这可能只有在您经常重用的情况下才值得。恕我直言,设计器非常适合原型设计或创建初始 UI 设计,但不适合长期维护。尽管设计器非常强大,但仍有许多选项未通过界面公开。

我建议研究一下 Qt 的自动连接功能。它尝试纯粹通过插槽命名约定建立连接。点击此处了解更多信息。我一直渴望尝试一下,但我们才刚刚进入 Qt 4 转换项目,我还没有机会。

As jopa said, if you want to do it in the Designer, you need to make the Designer aware of your component, which is probably only worthwhile if it is something you will reuse often. IMHO, the Designer is great for prototyping or creating an initial UI design, but not so good for long term maintenance. Although, the Designer is very powerful, there are a number of options that aren't exposed through the interface.

I suggest looking into the Qt's auto-connect capabilities. It attempts to make connection purely through a slot naming convention. Read more here. I've been itching to try this out, but we are only just getting into our Qt 4 conversion project and I haven't had a chance yet.

亚希 2024-09-12 18:12:17

将新类型的对象引入 Designer 的唯一方法是通过插件,但这仅适用于小部件,通过 QDesignerCustomWidgetCollectionInterface 实现。如果 Designer 允许像 Apple 的 Interface Builder 那样连接到其他对象,那就太好了,但这是不可能的。现在,我们需要在表单的构造函数中连接这些信号。

The only way to introduce new types of objects into Designer is via a plugin, but that only works for widgets, via QDesignerCustomWidgetCollectionInterface. It would be nice if Designer allowed connections to other objects just like Apple’s Interface Builder allows, but it is not possible. For now, we are left connecting such signals in the form’s constructor.

深巷少女 2024-09-12 18:12:17

我从不使用 Qt Creator 的信号和槽编辑器,我总是使用 connect。将所有信号和槽连接集中在一处要容易得多,如果它们考虑正在使用的库(例如 QIODevice 中的 readyRead())或 GUI(例如 indexChanged(int)),则它们是独立的。

这使得代码更具可读性+我在信号和槽编辑器方面遇到了很多麻烦。

I do never use the signals and slots editor of the Qt Creator, I do always use connect. It is much easier to have all signal and slot connections at one place, independent if they regard a library being used (readyRead() from QIODevice for example) or the GUI (indexChanged(int) for example).

This makes the code more readable + I have experienced much trouble with the signals and slots editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文