QtCreator GUI open text file
I made a push button that will browse and get a textfile. But I need to
open it in a new window to check if the content of the textfile is
correct. How do I do this?
Also, I would like to have a line edit right next to the button that shows
which file I'm looking at. In other words, the directory of the file that
is opened through the button.
Currently, this is what I have:
void MainWindow::on_fileButton_clicked()
{
QString fileName1 = QFileDialog::getOpenFileName(this,tr("Open Text
File"), "", tr("Text Files (*.txt)"));
QFile file1(fileName1);
if(!file1.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file1);
while(!in.atEnd()){
QString line = in.readLine();
}
}
No comments:
Post a Comment