QT4 Designer - 实现小部件
我目前正在尝试进入 QT4 并为自己找出一个工作流程。
在尝试创建一个允许用户连接到主机名的小部件时:端口出现了一些问题。小部件本身包含一个用于输入主机名的 LineEdit、一个用于输入端口的 SpinBox 和一个应发出 connect(QString hostname, unsigned int port) 信号的 PushButton。
在 QTDesigner 中,我创建了必要的表单。它保存为 .ui 文件。现在最大的问题是我如何实现这个小部件? QTDesigner 中是否有一个地方可以将我的信号添加到小部件?我可以在哪里添加自定义属性?
我在另一个教程中学到了如何在 C++ 中创建 Widget,如何定义信号、槽、Q_PROPERTIES 等并将其添加到 Widget。但QTDesigner中没有源代码。
另一种选择是使用 uic 生成源代码。但标头表示,另一个生成将覆盖对源文件的任何更改。
那么,如何通过使用 QTDesigner 创建 UI 来完全使用自己的信号、槽和属性创建 QT 小部件,而不必在 UI 更改时重新编码所有内容。有某种往返工程吗?
如果那不可能:那么使用 QTDesigner 创建 Widget 的意义是什么?
I'm currently trying to get into QT4 and figure out a workflow for myself.
While trying to create a widget which allows the user to connect to a hostname:port some questions appeared. The widget itself contains a LineEdit for entering the hostname, a SpinBox for entering the port and a PushButton which should emit a connect(QString hostname, unsigned int port) signal.
In QTDesigner I created the necessary Form. It is saved as a .ui-File. Now the big question is how could I implement the widget? Is there a place in QTDesigner where I could add my signal to the Widget? Where could I add custom Properties?
I've learned in another tutorial, which showed how to create a Widget in C++, how signals, slots, Q_PROPERTIES etc are defined and added to the widget. But there is no sourcecode in QTDesigner.
Another option would be to generate sourcecode using uic. But the header says, that another generate would overwrite any changes to the sourcefiles.
So how can I create a QT-widget completely with my own signals, slots and properties by using the QTDesigner for creating the UI and not having to recode everything whenever the UI is changing. Is there some kind of Roundtrip-Engineering?
If thats not possible: Whats the sense of creating a Widget with QTDesigner then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我自己已经找到了答案。 (为什么需要 2-3 小时阅读教程等,直到我放弃并在 Stackoverflow 上提出问题,然后继续搜索 5 分钟后,我自己找到解决方案?-.-)
我认为 QT 文档的章节正在描述如何以可用的方式在自己的小部件中使用 uic 生成的文件。
http://doc.qt.nokia.com/4.0/ porting4-designer.html#uic-output
我的下一步将是使用第二种方法来创建具有我所需的信号和属性的小部件。
I think I've found the answer myself. (Why does it need 2-3h of reading through tutorials etc until I give up and ask the question at Stackoverflow and then 5min after continuing to search, I find the solution myself? -.-)
I think the chapter of the QT-Documentation is describing how to use uic-generated files in an own widget in a usable way.
http://doc.qt.nokia.com/4.0/porting4-designer.html#uic-output
My next step will be to use the second approach to create a Widget with my needed signal and properties.