0
QFile file("../studentdata/students.txt");
file.open(QIODevice::WriteOnly| QIODevice::Text);

qDebug()<<file.isOpen()<<file.isReadable()<<file.isWritable();

I want to open the file students.txt with relative path, but the qDebug result is false false false

YOUNG
  • 23
  • 1
  • 6

2 Answers2

0

Your working directory may not be what you expect. Check it with QDir::currentPath() . Also check the QFile error string, so print file.errorString() after failed opening. For instance your application may not have permissions to write to this file.

Rames
  • 918
  • 11
  • 27
-2
 QFile file("studentdata\students.txt");
 file.open(QIODevice::WriteOnly| QIODevice::Text);

change the slash - it prints true, false, true. (:

Mara Black
  • 1,666
  • 18
  • 23