PDA

View Full Version : how to create a text file form the dialog ui and write the text from the lineedit...



prasad1001
4th February 2014, 16:15
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...

anda_skoa
4th February 2014, 19:10
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,
_

prasad1001
5th February 2014, 05:56
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..

Radek
5th February 2014, 07:35
If you set file name by


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:

QFile file("/home/me/here/myfile.txt");

The file will be created in /home/me/here .

For example:


QString defDir = "/home/me/here/";
QString fileName1 = ui->lineEdit->text();
QFile file;

if( fileName1.contains('/') ) file.setFileName(fileName1); // if fileName1 contains a directory
else file.setFileName(defDir + fileName1); //else set default directory

if( file.open( ... ) )
{
...

prasad1001
5th February 2014, 08:34
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...

anda_skoa
5th February 2014, 09:23
Connect to the line edit's editingFinished() signal and perform the check in that slot.

Cheers,
_

prasad1001
5th February 2014, 09:45
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...

Lesiok
5th February 2014, 11:20
First of all : start reading the Qt manual.