Hi All,
One of my assignment questions asks me to display a screen where a user enters software name, date of release and if it is recommended or not. Then store the information.
I made a UI class derived from QDialog that display the fields.
I then made a “Software” class that has the three variables.
software::software(QString name, QDate rdate, QString recommend){
setName(name);
setDate(rdate);
setRecommend(recommend);
}
I then made a software writer class which takes the “Software” class object and writes the info to a text file.
SoftwareWriter::SoftwareWriter(software *mySoftware){
QString mFileName = "F:/mySoftware.txt";
QFile mFile(mFileName);
if (!mFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug()<< "Cannot open File";
return;
}
QTextStream out(&mFile);
out<< mySoftware->getName();
out<< " ";
out << mySoftware->getRecommend();
out<< " ";
out <<mySoftware->getDate().toString();
mFile.flush();
mFile.close();
I have added a “Add” button the the UI class. Which when clicked triggers
void InputGUI::on_pbAdd_clicked()
{
name = ui->leName->text();
rdate = ui->deDate->date();
recommend = "No";
if (ui->cb->isChecked()){
recommend = "Yes";
}
software * mySoftware = new software(name, rdate, recommend);
SoftwareWriter write(mySoftware);
}
My problem is whenever I click on the “Add” button a new file is created instead of the same file being used to store the information.
How do I fix that problem?
Thanks and Regards
Paawan
↧