Results 1 to 8 of 8

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

  1. #1
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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...

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    prasad1001 (5th February 2014)

  4. #3
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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:n_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..

  5. #4
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to create a text file form the dialog ui and write the text from the lineedit

    If you set file name by
    Qt Code:
    1. QFile file("myfile.txt");
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. QFile file("/home/me/here/myfile.txt");
    To copy to clipboard, switch view to plain text mode 
    The file will be created in /home/me/here .

    For example:
    Qt Code:
    1. QString defDir = "/home/me/here/";
    2. QString fileName1 = ui->lineEdit->text();
    3. QFile file;
    4.  
    5. if( fileName1.contains('/') ) file.setFileName(fileName1); // if fileName1 contains a directory
    6. else file.setFileName(defDir + fileName1); //else set default directory
    7.  
    8. if( file.open( ... ) )
    9. {
    10. ...
    To copy to clipboard, switch view to plain text mode 

  6. #5
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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...

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    prasad1001 (5th February 2014)

  9. #7
    Join Date
    Feb 2014
    Posts
    31
    Thanks
    7
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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...

  10. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,499
    Thanked 277 Times in 272 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to mask the lineEdit text with asterisks for password entry?

    First of all : start reading the Qt manual.

Similar Threads

  1. conversion of lineedit text to numeric form
    By sachinmcajnu in forum Newbie
    Replies: 3
    Last Post: 9th March 2011, 17:45
  2. Write on a text file from QString
    By Malek in forum Newbie
    Replies: 3
    Last Post: 27th December 2010, 19:27
  3. Write one value per line in text file
    By babygal in forum Newbie
    Replies: 11
    Last Post: 1st December 2010, 06:47
  4. How to write ByteArray into a text file?
    By babygal in forum Newbie
    Replies: 4
    Last Post: 11th October 2010, 04:19
  5. read and write content of lineedit widget in Other Form
    By validator in forum Qt Programming
    Replies: 1
    Last Post: 25th April 2008, 15:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.