Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QIODevice::read: device not open, help
I tried using below code to load "myfile.txt" and insert it to "QTextEdit" textarea,
inputFile.open(QIODevice::ReadOnly); QTextStream in(&inputFile); QString line = in.readAll(); inputFile.close(); ui->myTextArea->setPlainText(line);
But unfortunately, when i call this function, it return "QIODevice::read: device not open " on Application Output Window.
Eddy last edited by
You should first check if "myfile.txt" "exists ":https://qt-project.org/doc/qt-5/qfile.html#exists
If "exists" returns false, you need to add your/path/to/your/file.
See the link to the docs for more info.
To add to Eddy "myfile.txt" is a relative path, so your program will expect it in the same folder as the executable.
[quote author="okiewardoyo" date="1397992026"]@Eddy and @SGaist , hi guys, my "myfile.txt" is on the same folder as my cpp files, i think it will work without adding the path :) [/quote]Your .txt file needs to be in your "working directory":https://en.wikipedia.org/wiki/Working_directory. Usually, this is the folder that contains your .exe file, not your .cpp files.
@JKSH: hi, you're right, i will try it,, :)