I have a dialog that creates a file and writes some data to it. The problem is that if the file already exists, it is overwritten before I catch the original file existing. I have the file names stored in a QStringList and I think I need to pass the list to the dialog to verify if it exists before it gets written. Here is what I have currently to open the dialog
Qt Code:
  1. void gui::on_actionCreate_triggered()
  2. {
  3. CreateDialog *create = new CreateDialog(this);
  4. create->show();
  5.  
  6. connect(create, SIGNAL(nameAdded(QString)), this, SLOT(vehicle_name_entered(QString)));
  7. ...
  8. }
To copy to clipboard, switch view to plain text mode 
Then I check if a name is entered and open a new dialog if it is empty. This also where I believe I need to check if it already exists.
Qt Code:
  1. void CreateDialog::on_create_vehicle_btn_clicked()
  2. {
  3. // Check if name is entered.
  4. if(ui->vehicle_name_dialog_txtbox->text() == "")
  5. {
  6. NameDialog *name = new NameDialog(this);
  7. name->show();
  8.  
  9. connect(name, SIGNAL(name_Added(QString)), this, SLOT(update_name(QString)));
  10. return;
  11. }
  12. ...
  13. emit nameAdded(ui->vehicle_name_dialog_txtbox->text());
  14. ...
  15.  
  16. this->close();
  17. }
To copy to clipboard, switch view to plain text mode 
Or maybe in NameDialog?
Qt Code:
  1. void NameDialog::on_ok_btn_clicked()
  2. {
  3. emit name_Added(ui->name_txtbox->text());
  4.  
  5. this->close();
  6. }
To copy to clipboard, switch view to plain text mode 
Currently I have the checking done here where I add it to the file that stores the QStringList. The new dialog here is basically the same as the last one and simply asks for another name and says the old file will be over written otherwise.
Qt Code:
  1. void gui::vehicle_name_entered(QString filename)
  2. {
  3. read_vehicle_file();
  4. if(!filename.isEmpty())
  5. {
  6. file_label->setText(filename);
  7. // Check if exists,
  8. for(int i = 0; i < vehicle.size(); ++i)
  9. {
  10. if(filename == vehicle[i])
  11. {
  12. NewNameDialog *new_name = new NewNameDialog(this);
  13. new_name->show();
  14.  
  15. connect(new_name, SIGNAL(name_Added(QString)), this, SLOT(new_vehicle_name_entered(QString)));
  16. return;
  17. }
  18. }
  19. }
  20.  
  21. vehicle << filename;
  22.  
  23. QFile file("vehicleList.txt");
  24. if(!file.open(QFile::Append | QFile::Text))
  25. {
  26. return;
  27. }
  28. QTextStream out(& file);
  29. out << filename << "\n";
  30.  
  31. file.close();
  32. }
To copy to clipboard, switch view to plain text mode 
I have pretty much confused myself trying different approaches so I am hoping someone else can straighten me out and get me headed back in the right direction.