how to create a text file form the dialog ui and write the text from the lineedit...
hello qt experts,
i am a beginner in qt.. i am developing a simple application and in that i have a line edit in dialog...and i want to create text file and wrote the lineedit input to that text file..please help me...
Re: how to create a text file form the dialog ui and write the text from the lineedit
Have a look at QFile for handling the actual I/O and QTextStream for writing the QString from the line edit into the file.
Cheers,
_
Re: how to create a text file form the dialog ui and write the text from the lineedit
Thanks for the quick reply, actually my code is...
void New::on_pushButton_clicked()
{
QString fileName1=ui->lineEdit->text();
qDebug()<<fileName1;
QFile file(fileName1);
if(file.open(QIODevice::WriteOnly))
{
QTextStream stream(&file);
stream<< "Employ Name:"<<(ui->lineEdit->text()) <<"\n"<<"Employ ID:"<<(ui->lineEdit_2->text());
stream.flush();
file.close();
}
//exit(1);
close();
}
Actually the files are creating in my project folder...but how to save those files in a specific folder....
Thank in advance..
Re: how to create a text file form the dialog ui and write the text from the lineedit
If you set file name by
Code:
QFile file("myfile.txt");
The file will be created in the current working directory - in the project directory unless you have changed CWD.
The file name can contain a directory, for example:
Code:
QFile file("/home/me/here/myfile.txt");
The file will be created in /home/me/here .
For example:
Code:
QString fileName1
= ui
->lineEdit
->text
();
if( fileName1.contains('/') ) file.setFileName(fileName1); // if fileName1 contains a directory
else file.setFileName(defDir + fileName1); //else set default directory
if( file.open( ... ) )
{
...
Re: how to create a text file form the dialog ui and write the text from the lineedit
Thanks for the quick reply...
I have other issue...i.e...i want to wait until i get input form lineEdit to match with other string..please help me...
Re: how to create a text file form the dialog ui and write the text from the lineedit
Connect to the line edit's editingFinished() signal and perform the check in that slot.
Cheers,
_
how to mask the lineEdit text with asterisks for password entry?
Hello Qt Experts,
i want to use my lineEdit for the login form ....so how do I make the QLineEdit widget mask the text in it with circles or asterisks for password entry and how i get the entered text to a Qstring?
Thanks in Advance...
Re: how to mask the lineEdit text with asterisks for password entry?
First of all : start reading the Qt manual.