1

我有这个用于保存 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);
}
4

1 回答 1

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 类型的类变量;

于 2013-07-04T13:12:58.603 回答