Skip to content

Commit

Permalink
openmv: Fix IDE crashing from setting plain text.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Nov 22, 2024
1 parent 064fb3d commit 5793b31
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/plugins/openmv/openmvpluginconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,33 @@ void OpenMVPlugin::connectClicked(bool forceBootloader, QString forceFirmwarePat

if(document && document->displayName() == QStringLiteral("helloworld_1.py") && (!document->isModified()))
{
document->setPlainText(QString::fromUtf8(fixScriptForSensor(document->contents())));
QString filePath = Core::ICore::userResourcePath(QStringLiteral("examples/00-HelloWorld/helloworld.py")).toString();

QFile file(filePath);

if(file.open(QIODevice::ReadOnly))
{
QByteArray data = file.readAll();

if((file.error() == QFile::NoError) && (!data.isEmpty()))
{
data = fixScriptForSensor(data);

QFile reload(document->filePath().toString());

if(reload.open(QIODevice::WriteOnly))
{
bool ok = reload.write(data) == data.size();
reload.close();

if (ok)
{
QString error;
document->reload(&error);
}
}
}
}
}
}

Expand Down

0 comments on commit 5793b31

Please sign in to comment.