C++ 如何使用 QT Creator 在 LineEdit 中写入和读取文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6679607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to write and read a text to and from a LineEdit using QT Creator?
提问by skywak
I am working with QT Creator. I have a form that contains a push button and an Line Edit. I would like to print a string that i give programatically in this LineEdit.Secondly I would also like to the from the LineBox a string that I fill in and print it using QMessageBox.
我正在与 QT Creator 合作。我有一个包含按钮和行编辑的表单。我想打印一个我在此 LineEdit 中以编程方式给出的字符串。其次我还想从 LineBox 中打印一个我填写的字符串并使用 QMessageBox 打印它。
How to do it? Need some help. I don't know how to access the displayText() to write and read from a LineEdit.
怎么做?需要一些帮助。我不知道如何访问 displayText() 以从 LineEdit 写入和读取。
I would like to specify that I put the push button and the lineedit on the Form using drag and drop.
我想指定我使用拖放将按钮和 lineedit 放在表单上。
I am working in c++ under Ubuntu Appreciate.
我在 Ubuntu Appreciate 下使用 C++。
回答by Vinicius Kamakura
You use QLineEdit::setText()to change the text and QLineEdit::text()to read.
你QLineEdit::setText()用来改变文本和QLineEdit::text()阅读。
Your questions are very basic and show a clear lack of studying the documentation and experimenting thing yourself. Qt is one of the better documented frameworks out there and with lots of examples. Please take your time to go through them.
您的问题非常基本,并且明显缺乏自己研究文档和实验的情况。Qt 是最好的文档框架之一,并且有很多示例。请花点时间浏览它们。

