【问题标题】:how to check if file already exists in qt simple mediaplayer如何检查qt simple mediaplayer中是否已经存在文件
【发布时间】:2021-06-20 09:23:14
【问题描述】:

我有一个简单的媒体播放器,其中一个功能是播放器有一个打开的视频列表,我想创建一个附加功能,用于检查视频或“文件”是否已经打开并且阻止它打开我已经尝试过这样的事情,但它没有工作:

bool fileExists(QString path)= QFileInfo::exists(path).isFile();
if (fileExists(path)== true)
{ 
   qDebug() <<"file already exists";
}

【问题讨论】:

    标签: c++ qt openfiledialog


    【解决方案1】:

    这里没有意义:

    bool fileExists(QString path)= QFileInfo::exists(path).isFile();
    

    我给你的建议是定义一个方法:

    bool MainWindow::fileExists(QString path)
    {
        QFileInfo fi(path);
        return fi.exists(path) && fi.isFile();
    }
    

    以及使用它:

    QString path{"/myPathToFile/myVideo.mp4"};
    
    if (fileExists(path))
    {
       qDebug() << "file already exists";
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      • 2023-01-25
      相关资源
      最近更新 更多