ciao!
si hai ragione.
il metodo open ritoran un bool.
quindi in teoria mi basterebbe controllare se il file è aperto.
però ho provato ad usare le eccezioni in questo modo:
codice:
ReadHeaderTable::ReadHeaderTable(QString f) {
file = new QFile(f);
try {
file->open(QFile::ReadOnly | QFile::Text);
} catch (const std::exception& e) {
qDebug() << e.what();
}
}
QStringList ReadHeaderTable::setHeader() {
QStringList list;
if (file->isOpen()) {
while(!file->atEnd()) {
list.append(file->readLine().replace("\n", ""));
}
}
return list;
}
ReadHeaderTable::~ReadHeaderTable() {
try {
file->close();
} catch (const std::exception& e) {
qDebug() << e.what();
}
}
ho passato un file errato.
ma non è stato stampato nulla a video.
come se non fosse andato in eccezione-