如何在 Qt 中将数据从一种形式传递到另一种形式?
如何在 Qt 中将数据从一种表单传递到另一种表单?
我创建了一个 QWidgetProgect -> QtGuiApplication,我目前有两种形式。现在我想将数据从一种表单传递到另一种表单。
我怎样才能做到这一点?
谢谢。
How can I pass data from one form to another in Qt?
I have created a QWidgetProgect -> QtGuiApplication, I have two forms currently. Now I want to pass data from one form to another.
How can I achieve that ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是您可能想要尝试的一些选项:
textChanged
或textEdited
信号)信号和槽的示例:
假设您有两个窗口:
FirstForm
和SecondForm< /代码>。
FirstForm
在其 UI 上有一个QLineEdit
,名为myTextEdit
,SecondForm
有一个QListWidget
在其 UI 上,名为myListWidget
。我还假设您在应用程序的
main()
函数中创建了两个窗口。firstform.h:
firstform.cpp
secondform.h
secondform.cpp
main.cpp >
Here are some options that you might want to try:
textChanged
ortextEdited
signal)Example with Signals and Slots:
Let's assume that you have two windows:
FirstForm
andSecondForm
.FirstForm
has aQLineEdit
on its UI, namedmyTextEdit
andSecondForm
has aQListWidget
on its UI, namedmyListWidget
.I'm also assuming that you create both of the windows in the
main()
function of your application.firstform.h:
firstform.cpp
secondform.h
secondform.cpp
main.cpp
您还可以使用指针从其他表单访问 QTextEdit(假设您正在使用它)。
按照 Venemo 的示例(其中 FirstForm 具有 QTextEdit,SecondForm 具有您需要从中访问 QTextEdit 的 QTextEdit):
firstform.h:
firstform.cpp:
然后您可以访问QTextEdit 在 SecondForm 中的文本如下所示(假设您的 FirstForm 实例称为firstForm):
You could also use pointers to access the QTextEdit (assuming that's what you're using) from the other form.
Following from Venemo's example (where FirstForm has the QTextEdit and SecondForm's the one you need to access the QTextEdit from):
firstform.h:
firstform.cpp:
You can then access the QTextEdit's text in SecondForm with something like this (assuming your instance of FirstForm is called firstForm):