nine9hours 0 Newbie Poster

I wrote the following code, so that whenever an item from the list is deleted, the file associated with the name of the items below the delted items get updated. But the program isn't working, i have been reviewing this code for last 2 days but worthless. Please help.

void MainWindow::updatingitems()
{
    QFile files, itemfile, commentfile;


    for(int i=deleteditemposition;i<ui->listWidget->count();i++)
    {
        if(i==deleteditemposition)
        {
            files.setFileName("E:/"+QString::number(deleteditemposition)+".txt");
            files.remove();
        }
        else
        {
            files.setFileName("E:/"+QString::number(i)+".txt");
            itemfile.setFileName("E:/"+QString::number(i-1)+".txt");
            commentfile.setFileName("E:/"+QString::number(i-1)+".txt");
            if(files.open(QFile::ReadOnly) && itemfile.open(QFile::WriteOnly) && commentfile.open(QFile::WriteOnly)  )
            {
                QTextStream in(&files);
                QTextStream out(&itemfile);
                out<< in.readAll();

                files.remove();
                itemfile.flush();
                itemfile.close();

                /* comment files new name updation after deletion has started*/
                files.setFileName("E:/"+QString::number(i)+prevname+".txt");
                commentfile.setFileName("E:/"+QString::number(i-1)+prevname+".txt");

                if(files.exists())
                {
                    if(files.open(QFile::ReadOnly)&& commentfile.open(QFile::WriteOnly))
                    {
                        QTextStream in(&files);
                        QTextStream out(&commentfile);

                        out<< in.readAll();

                        files.remove();

                        commentfile.flush();
                        commentfile.close();
                    }
                }
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.