I wrote the following code for retreiving data from a file(which already exists and permision is also given because i am on Windows OS), and creates items to display data fragments in a List, but the list won't show any thing. More over I figured out even when the file wasn't created, the FILE.EXISTS() function returned true. why is this so?
void MainWindow::on_listWidget_itemClicked(QListWidgetItem *item)
{
ui->listWidget_2->clear();
QListWidgetItem *itm=new QListWidgetItem;
ui->commentbutton->setEnabled(true);
QFile files("E:/"+QString::number(ui->listWidget->currentRow())+"com.txt");
if(files.exists())
{
if(!files.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this,"File Access!!!","The File containing data of the Items and Comments can't be acessed",QMessageBox::Ok);
return;
}
QTextStream in(&files);
QString data(in.readLine());
int x=0;
QString temp;
for(int i=0;;i++)
{
if(data.at(i)!='@' && data.at(i+1)!='#')
{
temp[x]=data.at(i);
x++;
}
else
if(data.at(i)=='@' && data.at(i+1)=='#')
{
x=0;
i++;
itm->setText(temp);
ui->listWidget_2->addItem(itm);
}
if(data.end())
break;
}
files.close();
}
the path at which the files are generated displays:
This is the data stored in 0com.txt file (comment file): NewYork@#London@# Thanks for your time!
QFile files(...)
line. The thing in the parenthesis is a generated path. Please display that. – Mat