1. 创建文件夹、文件,写文件: void RegisterViewer::procSaveEvent() { QString name = registerTree->currentIndex().data().toString(); QString path("..//Register_Info//"); if(!registerTree->currentIndex().parent().isValid()) return; name.push_front("_"); name.push_front(registerTree->currentIndex().parent().data().toString()); name.append(".txt"); QDir *registers = new QDir; if(!registers->exists(path)) registers->mkdir(path); name.push_front(path); QFile file(name); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream in(&file); in<<"Update at: "<<QDateTime::currentDateTime().toString()<<endl<<endl; for(int i=0 ; i< model->rowCount(registerTree->currentIndex()); i++){ for(int j=0; j<4; j++){ in << registerTree->currentIndex().child(i,j).data().toString() <<" "; } in << endl; } file.close(); }