Lab: Use Results to Avoid Warning (#9156)

## Summary of Changes

Check that `open()` worked to avoid warnings
[here](https://cgal.geometryfactory.com/CGAL/testsuite/CGAL-6.2-Ic-50/Lab_Demo/TestReport_cgaltest_ArchLinux-clang-CXX20-Release.gz).

## Release Management

* Affected package(s): Lab

* License and copyright ownership: unchanged
This commit is contained in:
Sebastien Loriot 2025-12-03 11:52:48 +01:00 committed by GitHub
commit def6c38d76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 27 deletions

View File

@ -1795,8 +1795,8 @@ bool MainWindow::loadScript(QFileInfo info)
QString program; QString program;
QString filename = info.absoluteFilePath(); QString filename = info.absoluteFilePath();
QFile script_file(filename); QFile script_file(filename);
script_file.open(QIODevice::ReadOnly); bool success = script_file.open(QIODevice::ReadOnly);
if(!script_file.isReadable()) { if((! success) || (!script_file.isReadable())) {
throw std::ios_base::failure(script_file.errorString().toStdString()); throw std::ios_base::failure(script_file.errorString().toStdString());
} }
program = script_file.readAll(); program = script_file.readAll();
@ -2747,9 +2747,9 @@ void MainWindow::exportStatistics()
if(filename.isEmpty()) if(filename.isEmpty())
return; return;
QFile output(filename); QFile output(filename);
output.open(QIODevice::WriteOnly | QIODevice::Text); bool success = output.open(QIODevice::WriteOnly | QIODevice::Text);
if(!output.isOpen()){ if((! success) || (!output.isOpen())){
qDebug() << "- Error, unable to open" << "outputFilename" << "for output"; qDebug() << "- Error, unable to open" << "outputFilename" << "for output";
} }
QTextStream outStream(&output); QTextStream outStream(&output);

View File

@ -93,18 +93,20 @@ bool Camera_positions_list::save(QString filename) {
if(m_model->rowCount() <1) if(m_model->rowCount() <1)
return false; return false;
QFile file(filename); QFile file(filename);
file.open(QIODevice::WriteOnly); if(file.open(QIODevice::WriteOnly)){
QTextStream out(&file); QTextStream out(&file);
for(int i = 0; i < m_model->rowCount(); ++i) for(int i = 0; i < m_model->rowCount(); ++i)
{ {
QStandardItem* item = m_model->item(i); QStandardItem* item = m_model->item(i);
out << item->data(Qt::DisplayRole).toString() out << item->data(Qt::DisplayRole).toString()
<< "\n" << "\n"
<< item->data(Qt::UserRole).toString() << item->data(Qt::UserRole).toString()
<< "\n"; << "\n";
}
file.close();
return true;
} }
file.close(); return false;
return true;
} }
void Camera_positions_list::on_saveButton_pressed() void Camera_positions_list::on_saveButton_pressed()
@ -129,19 +131,24 @@ void Camera_positions_list::on_openButton_pressed()
void Camera_positions_list::load(QString filename) { void Camera_positions_list::load(QString filename) {
QFile file(filename); QFile file(filename);
std::clog << "Loading camera positions " << qPrintable(filename) << std::endl;
file.open(QIODevice::ReadOnly); if(file.open(QIODevice::ReadOnly)){
QTextStream input(&file); std::clog << "Loading camera positions " << qPrintable(filename) << std::endl;
while(!input.atEnd()) {
QString text = input.readLine(1000); QTextStream input(&file);
QString coord = input.readLine(1000); while(!input.atEnd()) {
if(text.isNull() || coord.isNull()) return; QString text = input.readLine(1000);
CGAL::qglviewer::Frame frame; QString coord = input.readLine(1000);
if(Three::activeViewer()->readFrame(coord, frame)) if(text.isNull() || coord.isNull()) return;
{ CGAL::qglviewer::Frame frame;
addItem(text, if(Three::activeViewer()->readFrame(coord, frame))
Three::activeViewer()->dumpFrame(frame)); {
addItem(text,
Three::activeViewer()->dumpFrame(frame));
}
} }
}else {
std::clog << "Loading camera positions " << qPrintable(filename) << " failed" << std::endl;
} }
} }