Results 1 to 3 of 3

Thread: QLabel to textfile

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question QLabel to textfile

    I want to put the data from a QLabel/QLineEdit in a text file.

    But when I do it like this:
    Qt Code:
    1. void MainWindow::on_pushButton_3_clicked() //the smile = : o
    2. {
    3. QFile file("test.txt");
    4. if (!file.open(QIODevice::Append | QIODevice::Text))
    5. return;
    6. QTextStream out(&file);
    7. out << this->ui->naamLineEdit;
    8. out << "\r\n";
    9. }
    To copy to clipboard, switch view to plain text mode 
    where naamLineEdit is the name of my QLineEdit, and my input is: test.
    It puts this in the txt file:
    0xb18da40

    Same goes for:
    Qt Code:
    1. out << this->ui->tijdLabel_2;
    To copy to clipboard, switch view to plain text mode 
    where tijdLabel_2 is the name of my QLabel.
    It also puts a strange string in the text file.

    Can someone help me out, I think it's fault with not converting/storing the QLineEdit/QLabel the right way.
    Last edited by high_flyer; 10th May 2011 at 14:47. Reason: code tags

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QLabel to textfile

    That is because naamLineEdit is a pointer to your QLineEdit.
    And you will need to call the text() member function to return the text as a QString, so code will become something like:
    Qt Code:
    1. out << this->ui->naamLineEdit->text();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLabel to textfile

    Thank you Zlatomir,
    It works with my QLineEdit and QLabel.

Similar Threads

  1. Replies: 4
    Last Post: 17th September 2010, 20:18
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Load textfile content into a textEdit
    By gt.beta2 in forum Newbie
    Replies: 1
    Last Post: 3rd March 2009, 22:57
  4. Replies: 1
    Last Post: 2nd August 2008, 15:46
  5. loading a textfile in a qlabel
    By harakiri in forum Newbie
    Replies: 5
    Last Post: 12th June 2007, 09:08

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.