Skip to content

Commit 5793b31

Browse files
committed
openmv: Fix IDE crashing from setting plain text.
1 parent 064fb3d commit 5793b31

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/plugins/openmv/openmvpluginconnect.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,33 @@ void OpenMVPlugin::connectClicked(bool forceBootloader, QString forceFirmwarePat
24412441

24422442
if(document && document->displayName() == QStringLiteral("helloworld_1.py") && (!document->isModified()))
24432443
{
2444-
document->setPlainText(QString::fromUtf8(fixScriptForSensor(document->contents())));
2444+
QString filePath = Core::ICore::userResourcePath(QStringLiteral("examples/00-HelloWorld/helloworld.py")).toString();
2445+
2446+
QFile file(filePath);
2447+
2448+
if(file.open(QIODevice::ReadOnly))
2449+
{
2450+
QByteArray data = file.readAll();
2451+
2452+
if((file.error() == QFile::NoError) && (!data.isEmpty()))
2453+
{
2454+
data = fixScriptForSensor(data);
2455+
2456+
QFile reload(document->filePath().toString());
2457+
2458+
if(reload.open(QIODevice::WriteOnly))
2459+
{
2460+
bool ok = reload.write(data) == data.size();
2461+
reload.close();
2462+
2463+
if (ok)
2464+
{
2465+
QString error;
2466+
document->reload(&error);
2467+
}
2468+
}
2469+
}
2470+
}
24452471
}
24462472
}
24472473

0 commit comments

Comments
 (0)