Unsolved Delete file correct defination in C++
-
Hi,
How to write correct defination of delete picture from default system picture .Here is below my code in C++ :
void deleteFile()
{QString parameter ="/storage/sdcard0/Pictures/{CB6942CE-8FDE-B00F-A07E-832ECAE05AF4}_1.jpg" // QString parameter ="file:///storage/sdcard0/Pictures/{CB6942CE-8FDE-B00F-A07E-832ECAE05AF4}_1.jpg" bool state=QFile::remove(parameter); if(state==true) { qDebug() << "delete successful"; } else { qDebug() << "delete unsuccessful"; }
}
Both of them parameter paths I've tried but ppplication output is like below:
D/OfflineTests( 4216): (null):0 ((null)): delete unsuccessful
How can I write correct delete code ?
Thanks
-
Hi!
Are you sure the file you want to delete actually exists? The following works for me:void MainForm::on_pushButton_clicked() { const QString fileName = QString("%1/myfile.txt").arg( QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) ); ui->pushButton->setText( QFile::remove(fileName) ? ":-)" : ":-(" ); }
-
Thanks dolved problem