user3874443
user3874443

Reputation:

C++ Qt cannot read the whole text file

I'm writing a tool for private use. The problem is that Qt cannot read a text file containing all contents published here.

It only reads this The three points were pasted by Qt.

My code for reading the file is following

QFile file;
file.setFileName(m_filename);
if (!file.open(QIODevice::ReadOnly))
    return;

QTextStream in(&file);

while (!in.atEnd()) {
    m_fileContents += in.readLine();
}
file.close();

Do you have any idea why it doesn't work?

Upvotes: 0

Views: 400

Answers (2)

Forbinn
Forbinn

Reputation: 75

I just tested your code on my own computer with your data and it works well. If you're using an IDE, maybe it does not display all the text of your final string and this is why you have three dot at the end of your sample.

Also as evilruff suggest you can use QFile::readAll method directly.

Upvotes: 0

evilruff
evilruff

Reputation: 4085

QFile file;
file.setFileName(m_filename);
if (!file.open(QIODevice::ReadOnly))
    return;

m_fileContents = file.readAll();

Upvotes: 1

Related Questions