Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how can i delete a file ?



  • Am selecting a file using combobox, combobox has the list of .xml files like this

    QSettings oSettings(QLatin1String("Main"),QLatin1String("Sub"));
     oSettings.setFallbacksEnabled(false);
     oSettings.beginGroup("dedup");
     
     QStringList files = qVariantValue<QStringList>(oSettings.value("templateprofilepath"));
     QString strPath_2 = files.join("");
     QDir oDir_2(strPath_2);
     QStringList strFileFilterLst_2;
     QStringList strLstFiles_2 = oDir_2.entryList(strFileFilterLst_2,QDir::Files | QDir::NoDotAndDotDot);
     strLstFiles_2.replaceInStrings(".xml", "", Qt::CaseInsensitive);
     strLstFiles_2.prepend("");
    
     QWidget *window_A = new QWidget;
     QLabel *label = new QLabel(" ");
     label = new QLabel("<b>Select Profile Name:</b>");
    
    combo = new QComboBox();
    combo->addItems(strLstFiles_2);
    

    templateprofilepath is the location of the dir
    now i want to delete the file selected by the combobox , please help me am struck here.

    Thanks in advance.

    sorry for my english


  • Lifetime Qt Champion

    Hi
    You need full path to file ( with filename)
    Then do
    QFile file (Fullpathtofile);
    file.remove();

    so I guess something like
    QString FullFile= templateprofilepath + "/" + FileNameFromCombo



  • @mrjj

    then the FullFile path is looks like this D:\logs/file.xml
    how can i change the path?


  • Lifetime Qt Champion

    just use "\"

    QString FullFile= templateprofilepath + "\\" + FileNameFromCombo
    NOTE: you MUST use 2 of them. 
    


  • @mrjj
    thanks a lot :)


Log in to reply