[英]reading a file into Qt
I wrote a Program in Qt 5.2.1 that writes some data into a file and now I want to read it and display it. 我在Qt 5.2.1中编写了一个程序,该程序将一些数据写入文件,现在我想读取并显示它。 ( in a text edit or any other widget) (在文本编辑或任何其他小部件中)
Here is my code ( the part I thought is relevant ) - 这是我的代码(我认为相关的部分)-
But i don't get the desires result ... could you look into it and tell me what i an doing wrong 但是我没有得到欲望的结果...你能调查一下并告诉我我做错了什么吗
void MainWindow::on_Search_clicked()
{
QString name ;
name = ui->Search_name->text();
QFile readfile("data.txt");
if(!readfile.open(QIODevice::ReadOnly))
{
qDebug() << "error opening file: " << readfile.error();
return;
}
QTextStream instream(&readfile);
QString line = instream.readLine();
// ui->text is a QPlainTextEdit*
ui->text->insertPlainText(line);
readfile.close();
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.