I am trying to access .h and .cpp files in a selected folder. My goal is to find and print on MainWindow how many lines in .h and .cpp files. In my code, there is no problem to access to selected folder. But for example, what if a .txt file is in this folder, I do not want to count lines of .txt file. My code is here:
int countLine::funcCountLines(QString fullPath)
{
int counter = 0;
QFile file(fullPath);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return 0;
}
while(!file.atEnd())
{
QByteArray line = file.readLine();
counter++;
}
return counter;
}
Best regards!
You can use
QDir::setNameFiltersto retrieve only the files you are interested in.