All,
Running the following file in Qt Creator on a Macbook Pro 19.6.2.
#include <QTextStream>
#include <QDir>
int main()
{
QTextStream out(stdout);
QDir dir;
QStringList filters;
filters << "*.cpp" << "*.o";
dir.setNameFilters(filters);
QFileInfoList list = dir.entryInfoList();
for (int i=0; i<list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
out << QString("%1").arg(fileInfo.fileName());
out << endl;
}
}
The directory contains some .cpp and .o files,
david-arnolds-macbook-pro-2:Filters darnold$ pwd
/Users/darnold/Documents/temp/myQt/zetcode/Filters
david-arnolds-macbook-pro-2:Filters darnold$ ls -ll
total 456
drwxr-xr-x 3 darnold staff 102 Mar 29 16:52 Filters.app
-rw-r--r-- 1 darnold staff 23 Mar 29 16:44 Filters.pro
-rw-r--r-- 1 darnold staff 7820 Mar 29 17:04 Filters.pro.user
-rw-r--r-- 1 darnold staff 9213 Mar 29 16:52 Makefile
-rw-r--r-- 1 darnold staff 404 Mar 29 17:21 filters.cpp
-rw-r--r-- 1 darnold staff 204600 Mar 29 17:22 filters.o
However, when I run Fileters.app from Qt Creator, here is the output:
Starting /Users/darnold/Documents/temp/myQt/zetcode/Filters/Filters.app/Contents/MacOS/Filters...
/Users/darnold/Documents/temp/myQt/zetcode/Filters/Filters.app/Contents/MacOS/Filters exited with code 0
Now (remember I'm on a Mac) if I "Show Package Contents" for Fileters.app, and drop the files filters.cpp and filters.o in /Users/darnold/Documents/temp/myQt/zetcode/Filters/Filters.app/Contents/MacOS/Filters, then "Run" the file again from QtCreator, I get:
/Users/darnold/Documents/temp/myQt/zetcode/Filters/Filters.app/Contents/MacOS/Filters...
filters.cpp
filters.o
/Users/darnold/Documents/temp/myQt/zetcode/Filters/Filters.app/Contents/MacOS/Filters exited with code 0
Should I be constructing my code differently if I want to view the contents of the directory /Users/darnold/Documents/temp/myQt/zetcode/Filters/?
David.
Bookmarks