I am writing a main text editor where I want to edit HTML files. I currently have a QTextEdit where I can write text and then save to a file / open from a file.
The problem is that when I open the HTML file, it does not open like plain text. Rather, it opens as processed HTML. This happens even if I save as .txt. Therefore i can write
<html> <h1>Test</h1> </html>
in a text element, save it as a text file. But if I open it, it suddenly processes HTML. The same thing happens when I open Html files that are saved from Notepad ++.
How can I open a file in plain text, how does notepad do it?
Here is the code that I have at the moment:
void Notepad::on_actionOpen_triggered() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), tr("Text Files (*.txt);;C++ Files (*.cpp *h);;All types (*.*)")); if (!fileName.isEmpty()) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { QMessageBox::critical(this, tr("Error"), tr("Could not open file")); return; } QTextStream in(&file); ui->textEdit->setText(in.readAll()); file.close(); } }
source share