Why will Qt not create a text file when running or debugging from inside Qt, but will create it when directly from the debug folder?

StackOverflow https://stackoverflow.com/questions/18732094

Question

I am creating then writing to a text file using QTextStream. The problem is that the file is created if I build the application and run it from folder it creates, but if I run it from inside Qt in either release or debug mode it doesn't create the file. Does anyone have any suggestions? I am using a Macbook Pro.

Était-ce utile?

La solution

You probably used a relative path, and inside QtCreator the "current directory" from where the executable is ran is not necessarily the directory where the executable is.

Try:

qDebug() << QDir::currentPath();

It will tell you where you should expect your file to be written.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top