Hello All,

I'm trying to build a window to provide a space to the user to enter a file name to save/create file with the entered name. I want to associate the LineEdit(entered filename) with the PushButton(Save Button) so that when the user types in a name (say log) and hits the save button a file needs to be created along with the extension (like this: log.csv). This is where I've got so far. Please help.

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QApplication>
  4. #include <QFileDialog>
  5. #include <QDebug>
  6. #include <QFile>
  7. #include <QIODevice>
  8.  
  9.  
  10. MainWindow::MainWindow(QWidget *parent) :
  11. QMainWindow(parent),
  12. ui(new Ui::MainWindow)
  13. {
  14. ui->setupUi(this);
  15. }
  16.  
  17. MainWindow::~MainWindow()
  18. {
  19. delete ui;
  20. }
  21.  
  22. void MainWindow::on_pushButton_clicked()
  23. {
  24. QString fileName = QFileDialog::getSaveFileName(this, tr("Save Logs"),"/Tmp/",tr("(*.csv)"));
  25. if(!fileName.isEmpty())
  26. {
  27. QFile f(fileName);
  28. f.open(QIODevice::WriteOnly);
  29. f.close();
  30. }
  31. }
  32.  
  33. void MainWindow::on_lineEdit_editingFinished()
  34. {
  35.  
  36. }
To copy to clipboard, switch view to plain text mode 

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include"ui_mainwindow.h"
  6.  
  7. namespace Ui {
  8. class MainWindow;
  9. }
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13. Q_OBJECT
  14.  
  15. public:
  16. explicit MainWindow(QWidget *parent = 0);
  17. ~MainWindow();
  18.  
  19. private slots:
  20. void on_pushButton_clicked();
  21.  
  22. void on_lineEdit_editingFinished();
  23.  
  24. private:
  25. Ui::MainWindow *ui;
  26. };
  27.  
  28. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

Also, if someone could explain tr("Save Logs") part in the syntax of QString fileName = QFileDialog::getSaveFileName(this, tr("Save Logs"),"/Tmp/",tr("(*.csv)")); . That would be really helpful. Thanks in advance.