如何检查文件是否已存在于qt simple mediaplayer

问题描述

我有一个简单的媒体播放器,其中一个功能是播放器有一个打开的视频列表,我想创建一个额外的功能,它检查视频或“文件”是否已经打开并且阻止它打开我尝试过类似的东西,但没有用:

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

解决方法

这里没有意义:

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";
}