title: How to get file name in Qt?
body: <p>I have modified the Text Finder example which I got from a Qt Tutorial and made a Text Viewer. In this program, the user types in the address of the file and clicks the Search button. The program then displays the content of the text file.  Below is my code.
  text_finder.cpp:</p>
  
  <pre><code>#include "text_finder.h"
  #include "ui_text_finder.h"
  #include &lt;QHBoxLayout&gt;
  #include &lt;QFile&gt;
  #include &lt;QTextStream&gt;
  #include &lt;QFileDialog&gt;
  
  Text_Finder::Text_Finder(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::Text_Finder)
  {
      ui-&gt;setupUi(this);
  }
  
  Text_Finder::~Text_Finder()
  {
      delete ui;
  }
  
  void Text_Finder::loadFile(QFile file){ // I have to pass the file name as parameter.
      QFile inputFile(file);
      inputFile.open(QIODevice::ReadOnly);
      QTextStream in(&amp;inputFile);
      QString line = in.readAll();
      inputFile.close();
  
      ui-&gt;read-&gt;setText(line);
      QTextCursor cursor = ui-&gt;read-&gt;textCursor();
      cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
  }
  
  void Text_Finder::on_search_clicked()
  {
  //  Code that gets the path from the text box.
      loadFile();//Parameters not passed yet.
  }   
  </code></pre>
  
  <p>I have not yet entered the code which gets the name of the file from the address of the text box. I will have to pass the file to the loadFile() function which will enter the contents into the Text Edit in the center of the program. I want a solution to get the name of the file of which the user enters. For example, the user might enter, "/home/user/input.txt". The program should get the contents of that file and forward it to loadFile(). An solution with an explanation on how the various parts work is needed. I am using Qt Creator on Ubuntu 15.04 (Beta).</p>