how to set a text in line edit Qt Creator?
I am working in c++ Qt Creator. I have a form with label
s and lineEdit
s. I would like to set开发者_运维问答 as default in each lineEdit
a text. It would be more efficient than writing the same stuff each time I run the application. Can you please tell me how to do this?
Qt has a concept of properties, and for each property, there's usually a getter and a setter, in your case "Text" (as also displayed in the designer) -> void setText(QString)
, QString text()
.
As a serious advice: Learn to use the excellent documentation. Nearly everything in QtCreator lets you open a context-sensitive help via F1. And read some introductions;
Use
void setText( const QString & )
You can set it in the constructor or maybe set all those defaults in an init()
function.
Read thorugh the documentation.
Why not just set it to your default value at start? Would be the easiest way if you know how to set a textedit to a value anyhow.
hope this helps, tell me if you need aything more
When you double click in the UI designer on the QTextEdit
you can enter a default text which is set every time your application is run.
Alternate you can set the text using setText(QString)
function in the constructor of your window.
精彩评论