Qt自动保存XML文件

时间:2013-07-04 13:04:12

标签: c++ xml qt

我有这个代码用于保存XML文件并且它正常工作,但在此代码中,用户可以设置文件名和位置,我需要的是自动保存我的xml文件而不提示用户选择文件名或位置

void filech::saveMission(){



 QString  fileName = QFileDialog::getSaveFileName( this,  "Save a mission" , "C:/Users/",  "KML files (*.kml)"  );

      if ( !fileName.isEmpty() ) {
          manager->saveRoute(fileName);

       }



    myMission.saveMission(wpList,fileName);
}

1 个答案:

答案 0 :(得分:1)

所以你只需将其拆分并重载函数:

void filech::saveAsMission(){
 QString  fileName = QFileDialog::getSaveFileName( this,  "Save a mission" , "C:/Users/",  "KML files (*.kml)"  );
 saveMission(fileName);
}

void filech::saveMission(){
    saveMission(m_fileName);
}

void filech::saveMission(QString fileName){
     if ( !fileName.isEmpty() ) {
          manager->saveRoute(fileName);
          m_fileName = fileName;
       }
    myMission.saveMission(wpList,fileName);
}

m_fileName是QString类型的类变量;