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

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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top