Important: Please read the Qt Code of Conduct -

Opening a File at QDir

  • Hello Everyone,

    I'm iterating over files in a folder with QDir und QStringList. With isDir I'm checking if it's a Folder or a Directory. If it's a Folder I want to open it and manipulate the content. Here's the Code:

    QDir ProjectPath("C:\\Users\\X240\\Desktop\\Masterarbeit\\ZF-Schulungssystem\\ZF-Schulungssystem\\TwinCAT\\");
    		int count = 0;
    		QStringList fileNameList = ProjectPath.entryList();
    		for (QStringList::iterator iter = fileNameList.begin(); iter != fileNameList.end(); iter++ )
    			//check if *iter is directory of File
    			bool isDir =*iter);
    			if (!isDir) {
    				printf("checking if the configuration exists\n");
    				QString ZFsolutionName =;
    				QFile TCFile (ProjectPath + ZFsolutionName + ".sln"); 
    				if (!TCFile.exists())
    					printf(QString(ZFsolutionName + " does not exist\n").toStdString().c_str());


    QFile TCFile (ProjectPath + ZFsolutionName + ".sln");

    didn't work.

    How i can open files at the given Path?? How to convert the QDir to a QString ??


  • @JohnSRV said in Opening a File at QDir:

    How to convert the QDir to a QString ??

    QString QDir::dirName() const
    QString QDir::absolutePath() const
    QString QDir::absoluteFilePath(const QString &fileName) const
    QString QDir::canonicalPath() const
    QString QDir::filePath(const QString &fileName) const
    QFileInfoList QDir::entryInfoList(...) const
    QString QFileInfo::absoluteFilePath() const

  • @JohnSRV

    QFile TCFile (ProjectPath.absolutePath() + ZFsolutionName + ".sln");

    This should probably work.

    Why aren't you using:

    FileInfo would give you already the information if file or directory. Furthermore, you may use filters to exclude folders for your case.
    FileInfo would give you also the absolute file path

Log in to reply