Writing to file but file is not created?
-
Here is my code. I'm trying to write to file. I can run my program and it runs fine, with no errors or debug errors, but the file is not created and nothing is written.
@
QFile file("output.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qDebug() << "error";
break;
}QTextStream stream(&file); stream << "yes"; file.close();
@
-
You might not be looking in the program's working directory. Add this to your code after you create your QFile:
@
QFileInfo fileInfo(file);
qDebug() << fileInfo.absolutePath();
@What is the path shown?
-
I looked in the directory path that it showed and nothing. Its my build directory.
-
Hi,
What error does QFile return ?
-
Hii pditty8811..
Why r you using break over here ..it is illegal to use..
I compiled and run your program it is working fine at my side ..and file is created too.Give a specified path to a file . -
Hi guys thanks for responding. The break is there because all of this is actually in a case statement. I pulled it out of the case and it still doesn't work. If I run file.exists(), the file exists, and it also shows me the absolutepath with FileInfo, but I am unable to find the file on my computer.
What the hell is going on? I have hidden files shown and OS files unhidden.
I'm stumped.
-
Again: what error does QFile::error() return if open fails ?
-
QFile::error returns 0
-
The open does not fail.
-
1
-
From the QFile documentation:[quote]QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '') is not supported.[/quote]
-
[quote author="JKSH" date="1389414113"]From the QFile documentation:[quote]QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '') is not supported.[/quote][/quote]
Tried it, no luck.
I'm using windows xp, and Windows 7. Both builds don't produce the file.
-
I FINALLY FIGURED IT OUT. It's and antivirus thing. AVAST wasn't letting me create the file. Shit balls. I wasted 2 days on that issue.
-
Ouch! I'm glad you've found a solution.