Exemple #1
0
static void
write_group (const char *filename, int pos)
{
  FILE *f;

  f = fopen (filename, "w");
  fprintf (f, "one:x:1:one");
  write_users (f, pos, 1);
  fprintf (f, "two:x:2:two");
  write_users (f, pos, 2);
  fprintf (f, "three:x:3");
  write_users (f, pos, 3);
  fclose (f);
}
void ExistingUserDialog::on_deleteButton_clicked()
{
    QFile username_file(FileName);
    //Gets the username being deleted
    QString user_delete = ui->playerListBox->currentText();

    //Displays warning if file is not writable
    if(!username_file.open(QIODevice::ReadWrite|QIODevice::Text))
        QMessageBox::warning(this,tr("Error!"),tr("Error with rvz_players.csv! No new user created"),
                                     QMessageBox::Ok);
    
    QTextStream write_users(&username_file);
    QString final_text; //final text to be saved on csv file
    
    for(int i = 0; i < playerList.length(); i++)
    {
        //Seperates the name line in name + extra components
        QStringList temp_list;
        temp_list = playerList.at(i).split(':');

        //checks if the name component matches the one being deleted
        if(temp_list.at(1) != user_delete)
            final_text.append(playerList.at(i) + "\n");
    }

    //deletes all user info on the file
    ui->deleteAllButton->clicked(true);

    //Writes the updated user info on file
    write_users << final_text;

    //closes file
    username_file.close();
    readFromPlayerFile(); //Reads new version of file to update combo box
}