Skip to content

Commit 141a670

Browse files
omichelCopilotCopilot
authored
Fixed QFile.open() compilation warnings and macos-13 CI tests (cyberbotics#6924)
* Fixed Qt file open compilation warnings * Initial plan * Fix updateStyleSheet() to only read files when open succeeds Co-authored-by: omichel <1264964+omichel@users.noreply.github.com> * Fixed lupdate and lrelease command line names on Windows * Reverted lrelease/lupdate to previous names * Simplified/factorized * Fixed consistency * Fixed used of now retired macOS-13 runner * Update src/webots/sound/WbWaveFile.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: omichel <1264964+omichel@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3e6ea77 commit 141a670

8 files changed

Lines changed: 45 additions & 24 deletions

File tree

.github/workflows/test_suite_mac.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
if: ${{ contains(github.event.pull_request.labels.*.name, 'test webots build') }}
2020
strategy:
2121
matrix:
22-
os: [macos-13]
22+
os: [macos-14]
2323
runs-on: ${{ matrix.os }}
2424
steps:
2525
- uses: actions/checkout@v3
@@ -33,7 +33,7 @@ jobs:
3333
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || contains(github.event.pull_request.labels.*.name, 'test distribution') || contains(github.event.pull_request.labels.*.name, 'test suite') }}
3434
strategy:
3535
matrix:
36-
os: [macos-13]
36+
os: [macos-14]
3737
runs-on: ${{ matrix.os }}
3838
steps:
3939
- uses: actions/checkout@v3
@@ -70,7 +70,7 @@ jobs:
7070
if: ${{ contains(github.event.pull_request.labels.*.name, 'test suite mac') }}
7171
strategy:
7272
matrix:
73-
os: [macos-13]
73+
os: [macos-14]
7474
runs-on: ${{ matrix.os }}
7575
steps:
7676
- uses: actions/checkout@v3
@@ -103,7 +103,7 @@ jobs:
103103
if: ${{ always() && !contains(github.event.pull_request.labels.*.name, 'test distribution') && !contains(github.event.pull_request.labels.*.name, 'test webots build') }}
104104
strategy:
105105
matrix:
106-
os: [macos-13]
106+
os: [macos-14]
107107
runs-on: ubuntu-latest
108108
steps:
109109
- name: Delete artifacts

src/webots/app/WbApplication.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ void WbApplication::loadWorld(QString worldName, bool reloading, bool isLoadingA
271271
emit preWorldLoaded(reloading);
272272
// create a file in tmp path for ipc extern controllers
273273
QFile loading_file(WbStandardPaths::webotsTmpPath() + "loading");
274-
loading_file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
274+
if (!loading_file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
275+
WbLog::warning(tr("Could not create loading signal file: '%1'.").arg(loading_file.fileName()));
275276

276277
bool isFirstLoad = (mWorld == NULL);
277278
delete mWorld;

src/webots/core/WbIniParser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ WbIniParser::WbIniParser(const QString &filename) {
2121
QFile file(filename);
2222
QString line;
2323
QString section;
24-
file.open(QIODevice::ReadOnly);
24+
if (!file.open(QIODevice::ReadOnly)) {
25+
mValid = false;
26+
return;
27+
}
2528
mValid = true;
2629
while (!file.atEnd()) {
2730
line = file.readLine();

src/webots/gui/WbGuiApplication.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -565,25 +565,26 @@ static void setDarkTitlebar(HWND hwnd) {
565565
void WbGuiApplication::updateStyleSheet() {
566566
mThemeLoaded = WbPreferences::instance()->value("General/theme").toString();
567567
QFile qssFile(WbStandardPaths::resourcesPath() + mThemeLoaded);
568-
qssFile.open(QFile::ReadOnly);
569-
QString styleSheet = QString::fromUtf8(qssFile.readAll());
568+
QString styleSheet;
569+
if (qssFile.open(QFile::ReadOnly))
570+
styleSheet = QString::fromUtf8(qssFile.readAll());
571+
else
572+
WbLog::warning(tr("Could not open theme file: '%1'.").arg(qssFile.fileName()));
570573

571574
#ifdef __APPLE__
572-
QFile macOSQssFile(WbStandardPaths::resourcesPath() + "stylesheet.macos.qss");
573-
macOSQssFile.open(QFile::ReadOnly);
574-
styleSheet += QString::fromUtf8(macOSQssFile.readAll());
575-
575+
const QString platformStylesheet = "stylesheet.macos.qss";
576576
#elif defined(__linux__)
577-
QFile linuxQssFile(WbStandardPaths::resourcesPath() + "stylesheet.linux.qss");
578-
linuxQssFile.open(QFile::ReadOnly);
579-
styleSheet += QString::fromUtf8(linuxQssFile.readAll());
580-
577+
const QString platformStylesheet = "stylesheet.linux.qss";
581578
#elif _WIN32
582-
QFile windowsQssFile(WbStandardPaths::resourcesPath() + "stylesheet.windows.qss");
583-
windowsQssFile.open(QFile::ReadOnly);
584-
styleSheet += QString::fromUtf8(windowsQssFile.readAll());
579+
const QString platformStylesheet = "stylesheet.windows.qss";
585580
#endif
586581

582+
QFile platformQssFile(WbStandardPaths::resourcesPath() + platformStylesheet);
583+
if (platformQssFile.open(QFile::ReadOnly))
584+
styleSheet += QString::fromUtf8(platformQssFile.readAll());
585+
else
586+
WbLog::warning(tr("Could not open stylesheet file: '%1'.").arg(platformQssFile.fileName()));
587+
587588
qApp->setStyleSheet(styleSheet);
588589
#ifdef _WIN32
589590
if (mThemeLoaded != "webots_classic.qss")

src/webots/gui/WbMainWindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,7 +2432,10 @@ void WbMainWindow::openFileInTextEditor(const QString &fileName, bool modify, bo
24322432
const QString webotsRepo = fileName.mid(0, index);
24332433

24342434
QFile localFile(fileToOpen);
2435-
localFile.open(QIODevice::ReadWrite);
2435+
if (!localFile.open(QIODevice::ReadWrite)) {
2436+
WbLog::error(tr("Could not open file for editing: '%1'.").arg(fileToOpen));
2437+
return;
2438+
}
24362439
const QString contents = QString(localFile.readAll());
24372440
QStringList lines = contents.split('\n');
24382441
for (QString &line : lines) {

src/webots/gui/WbNewWorldWizard.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "WbApplicationInfo.hpp"
1818
#include "WbFileUtil.hpp"
1919
#include "WbLineEdit.hpp"
20+
#include "WbLog.hpp"
2021
#include "WbMessageBox.hpp"
2122
#include "WbPreferences.hpp"
2223
#include "WbProject.hpp"
@@ -49,7 +50,10 @@ int WbNewWorldWizard::exec() {
4950

5051
void WbNewWorldWizard::createWorldFile() {
5152
QFile file(WbProject::current()->worldsPath() + fileName());
52-
file.open(QIODevice::WriteOnly);
53+
if (!file.open(QIODevice::WriteOnly)) {
54+
WbLog::error(tr("Could not create world file: '%1'.").arg(file.fileName()));
55+
return;
56+
}
5357
QByteArray worldContent;
5458
worldContent.append(QString("#VRML_SIM %1 utf8\n").arg(WbApplicationInfo::version().toString(false)).toUtf8());
5559
QStringList externProtoList;

src/webots/scene_tree/WbSceneTree.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,10 @@ void WbSceneTree::openTemplateInstanceInTextEditor() {
15931593
tmpDir.mkdir(generatedProtos);
15941594
QFile file(
15951595
QString("%1%2/%3.generated_proto").arg(WbStandardPaths::webotsTmpPath()).arg(generatedProtos).arg(node->proto()->name()));
1596-
file.open(QIODevice::WriteOnly | QIODevice::Text);
1596+
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1597+
WbLog::error(tr("Could not create temporary file: '%1'.").arg(file.fileName()));
1598+
return;
1599+
}
15971600
file.write(node->protoInstanceTemplateContent());
15981601
file.close();
15991602
if (!file.fileName().isEmpty())

src/webots/sound/WbWaveFile.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "WbWaveFile.hpp"
1616

17+
#include "WbLog.hpp"
1718
#include "WbStandardPaths.hpp"
1819

1920
#include <QtCore/QDir>
@@ -187,7 +188,11 @@ void WbWaveFile::loadConvertedFile(int side) {
187188
void WbWaveFile::loadConvertedFile(int side, const QString &filename) {
188189
assert(mDevice == NULL);
189190
mDevice = new QFile(filename);
190-
mDevice->open(QIODevice::ReadOnly);
191+
if (!mDevice->open(QIODevice::ReadOnly)) {
192+
delete mDevice;
193+
mDevice = NULL;
194+
throw QObject::tr("Could not open audio device: '%1'.").arg(filename);
195+
}
191196
loadConvertedFile(side);
192197
mDevice->close();
193198
delete mDevice;
@@ -216,7 +221,8 @@ void WbWaveFile::loadFromFile(const QString &extension, int side) {
216221
if (mDevice) {
217222
inputFilename = WbStandardPaths::webotsTmpPath() + "input." + extension;
218223
QFile input(inputFilename);
219-
input.open(QFile::WriteOnly);
224+
if (!input.open(QFile::WriteOnly))
225+
throw QObject::tr("Could not create temporary audio file: '%1'.").arg(inputFilename);
220226
input.write(mDevice->readAll());
221227
input.close();
222228
} else

0 commit comments

Comments
 (0)