public static void main(String args[]) {
    QApplication.initialize(args);

    new FindFiles().show();

    QApplication.execStatic();
    QApplication.shutdown();
  }
  // ! [5]
  private List<String> findFiles(QDir directory, List<String> files, String text) {
    QProgressDialog progressDialog = new QProgressDialog(this);
    progressDialog.setCancelButtonText(tr("&Cancel"));
    progressDialog.setRange(0, files.size());
    progressDialog.setWindowTitle(tr("Find Files"));

    // ! [5] //! [6]
    List<String> foundFiles = new LinkedList<String>();

    for (int i = 0; i < files.size(); ++i) {
      progressDialog.setValue(i);
      progressDialog.setLabelText(tr("Searching file number " + i + " of " + files.size() + "..."));
      QApplication.processEvents();

      if (progressDialog.wasCanceled()) break;
      // ! [6]

      // ! [7]
      QFile file = new QFile(directory.absoluteFilePath(files.get(i)));

      if (file.open(QIODevice.OpenModeFlag.ReadOnly)) {
        String line = "";
        QTextStream in = new QTextStream(file);
        while (!in.atEnd()) {
          if (progressDialog.wasCanceled()) break;
          line = in.readLine();
          if (line.contains(text)) {
            foundFiles.add(files.get(i));
            break;
          }
        }
      }
    }
    return foundFiles;
  }