修改转换Qt字符串路径为系统编码的C字符串(解决中文路径问题)实现代码
This commit is contained in:
parent
15d37e279e
commit
cbb56426ec
|
|
@ -769,7 +769,7 @@ bool EnergyScaleParticleDataTask::processTask()
|
|||
project_model->SetParticleEnergyDataFilename(energy_spectrum_filename);
|
||||
} catch (const std::exception& e) {
|
||||
out.close();
|
||||
std::remove(QStrToSysPath(energy_spectrum_filename));
|
||||
std::remove(QStrToSysPath(energy_spectrum_filename).c_str());
|
||||
const QString& e_what = QString::fromStdString(e.what());
|
||||
LOG_WARN(QStringLiteral(u"能谱数据处理异常:%1").arg(e_what));
|
||||
return false;
|
||||
|
|
@ -842,7 +842,7 @@ bool EnergyCountProcessTask::processTask()
|
|||
project_model->SetChannelEnergyCountDataFilename(channel_num, ch_out_filename);
|
||||
} catch (const std::exception& e) {
|
||||
ch_out.close();
|
||||
std::remove(QStrToSysPath(ch_out_filename));
|
||||
std::remove(QStrToSysPath(ch_out_filename).c_str());
|
||||
const QString& e_what = QString::fromStdString(e.what());
|
||||
LOG_WARN(QStringLiteral(u"%1能量计数异常:%2").arg(channel_name).arg(e_what));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
#include <QDebug>
|
||||
|
||||
// 转换Qt字符串路径为系统编码的C字符串(解决中文路径问题)
|
||||
static const char* QStrToSysPath(const QString& qstr_path)
|
||||
static std::string QStrToSysPath(const QString& qstr_path)
|
||||
{
|
||||
std::string sys_path; // 静态变量避免内存释放
|
||||
std::string sys_path;
|
||||
#ifdef Q_OS_WIN
|
||||
// Windows:转为GBK编码
|
||||
QTextCodec* gbkCodec = QTextCodec::codecForName("GBK");
|
||||
|
|
@ -20,7 +20,7 @@ static const char* QStrToSysPath(const QString& qstr_path)
|
|||
// Linux/Mac:转为UTF-8编码
|
||||
sys_path = qstr_path.toUtf8().toStdString();
|
||||
#endif
|
||||
return sys_path.c_str();
|
||||
return sys_path;
|
||||
}
|
||||
|
||||
static int ExtractNumberFromString(const QString& str) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user