Tip: This article is a learning record, if there is any error, please contact the author.
Article directory
foreword
When you were a kid, everyone encouraged you to grow and become a mature person who stopped being childish. However, there are few people who encourage you to continue to grow and become a person who doubts and resists the wrong trend of society.
--Paul Graham, Hacker and Painter.
1. Export – Custom Folder
When the software needs to export data, you can choose to customize the folder and choose the path to save.
QString strDir = QFileDialog::getExistingDirectory(
this
,tr("Open Directory")
,"/home"
,QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
if(strDir != "")
{
m_threadRun.m_strPath = strDir;
ui->LEdt_LogPath->setText(m_threadRun.m_strPath);
}
2. Export – Custom File
When the software needs to export data, you can choose to customize the selected file, such as txt, excel, log and other files.
QString strPath;
strPath = QFileDialog::getSaveFileName(this,"保存文件","G:","Excel File(*.xls,*.xlsx)");
QString strPath = QFileDialog::getSaveFileName(this,"保存文件","G:","File(*.txt)");
if(strPath != "")
{
}
3. Export – select folder
QDateTime time = QDateTime::currentDateTime(); //获取系统当前时间
QString info = time.toString("yyyy-MM-dd");
QString path=QCoreApplication::applicationDirPath()+"/"+"操作日志";/*保存log文件的路径*/
QDir dir(path);
if(!dir.exists()){
dir.mkdir(path);//新建文件夹
}
QString strPath = path + "/"+ info + "_log.txt";
QFile file(strPath);
bool isOK = file.open(QIODevice::WriteOnly|QIODevice::Append);//只写
if(isOK)
{
QString timestr = time.toString("yyyy-MM-dd hh:mm:ss.zzz");
QTextStream stream(&file);
stream<<timestr<<":"<<str<<"\r\n";
}
file.close();
4. Import – select file
QString strPath = QFileDialog::getOpenFileName(this,"保存文件","G:","File(*.txt)");
if(strPath != "")
{
}
Summarize
Good at summarizing, go further.