PDA

View Full Version : QLabel to textfile



jantje78
10th May 2011, 11:55
I want to put the data from a QLabel/QLineEdit in a text file.

But when I do it like this:

void MainWindow::on_pushButton_3_clicked() //the smile = : o
{
QFile file("test.txt");
if (!file.open(QIODevice::Append | QIODevice::Text))
return;
QTextStream out(&file);
out << this->ui->naamLineEdit;
out << "\r\n";
}
where naamLineEdit is the name of my QLineEdit, and my input is: test.
It puts this in the txt file:
0xb18da40

Same goes for:

out << this->ui->tijdLabel_2;
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.

Zlatomir
10th May 2011, 12:30
That is because naamLineEdit is a pointer to your QLineEdit.
And you will need to call the text() (http://doc.qt.nokia.com/latest/qlineedit.html#text-prop) member function to return the text as a QString, so code will become something like:

out << this->ui->naamLineEdit->text();

jantje78
11th May 2011, 09:53
Thank you Zlatomir,
It works with my QLineEdit and QLabel.
:D