gpt4 book ai didi

Qt-删除文件

转载 作者:行者123 更新时间:2023-12-04 02:41:53 24 4
gpt4 key购买 nike

我需要删除一个特定的文件。
我试过这个:

msgBox.setButtonText(QMessageBox::Ok , tr("Ok"));
msgBox.setButtonText(QMessageBox::Cancel , tr("Cancel"));

int ret = msgBox.exec();

switch (ret)
{
case QMessageBox::Ok:
{
#ifdef Q_OS_IOS
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
QString dbFile = paths.first().append("/log.dat");
#else
QString dbFile = "log.dat";
#endif
QSettings settings(CGlobalZone::m_companyName, CGlobalZone::m_softwareName);
settings.clear();
QDir dir;
dir.remove(dbFile);

break;

case QMessageBox::Cancel:
QTimer::singleShot(1500, this, SLOT(close()));
break;
}

但不幸的是 dbFile 仍然存在。如何删除“dbFile”?

最佳答案


    QFile file (dbFile);
file.remove();

代替
  QDir dir;
dir.remove(dbFile);

关于Qt-删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com