On Ubuntu/Debian platform I want to list all possible video sources using QDir in my Qt5 application by listing their device files under /dev
.
The code below works fine if I set myPath
to a dummy folder in in my home folder full of text files named video0, video1 etc. but once I try to list directly from /dev
it does not list any files at all.
QString myPath="/dev";// This works when I set it to my dummy folder /home/me/dev with dummy text files in it.
QDir dir;
dir.setPath(myPath);
QStringList filters;
filters<<"video?";
dir.setNameFilters(filters);
dir.setSorting(QDir::Name );
QFileInfoList list = dir.entryInfoList();
const int ct= list.size();
qDebug()<<"Found " <<QString::number(ct)<<" cameras";
for (int i = 0; i <ct; ++i) {
QFileInfo fileInfo = list.at(i);
qDebug()<<"Camera : "<<QString("%1 %2").arg(fileInfo.size(), 10).arg(fileInfo.fileName());
}
I can cd /dev && ls
just fine from the commandline so I know my user has access to list that dir. Also, there are no error messages or other indication that permission was denied. What is going on?
I found the answer in documentation literally seconds after posting my question and I feel a bit stupid now for not guessing it so here is the answer.
From documentation: