| 47 | } |
| 48 | |
| 49 | void FileViewDialog::loadTextFile(const QString &filename, QTextEdit *edit) |
| 50 | { |
| 51 | QFile file(filename); |
| 52 | if (!file.exists()) { |
| 53 | QString msg(tr("Could not find the file: %1")); |
| 54 | msg = msg.arg(filename); |
| 55 | |
| 56 | QMessageBox msgbox(QMessageBox::Critical, |
| 57 | tr("Cppcheck"), |
| 58 | msg, |
| 59 | QMessageBox::Ok, |
| 60 | this); |
| 61 | msgbox.exec(); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | (void)file.open(QIODevice::ReadOnly | QIODevice::Text); // TODO: check result |
| 66 | if (!file.isReadable()) { |
| 67 | QString msg(tr("Could not read the file: %1")); |
| 68 | msg = msg.arg(filename); |
| 69 | |
| 70 | QMessageBox msgbox(QMessageBox::Critical, |
| 71 | tr("Cppcheck"), |
| 72 | msg, |
| 73 | QMessageBox::Ok, |
| 74 | this); |
| 75 | msgbox.exec(); |
| 76 | return; |
| 77 | } |
| 78 | QByteArray filedata = file.readAll(); |
| 79 | file.close(); |
| 80 | |
| 81 | edit->setPlainText(filedata); |
| 82 | } |