Skip to content

Commit

Permalink
Change QProcess to work differently
Browse files Browse the repository at this point in the history
  • Loading branch information
tcorbly committed Nov 29, 2023
1 parent cfa3738 commit 680aaa3
Showing 1 changed file with 55 additions and 10 deletions.
65 changes: 55 additions & 10 deletions src/Create3Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,62 @@ int Create3Widget::isConnected()

void Create3Widget::resetServer()
{
QProcess *myProc = new QProcess();
QStringList args;
myProc->start("sudo podman stop -a");
myProc->waitForFinished();
QByteArray output = myProc->readAllStandardOutput();
qDebug() << output;
QProcess podmanStop;
QString podmanStopCommand = "sudo podman stop";
QStringList podmanStopArgs;
podmanStopArgs << "-a";

myProc->start("sudo podman run -dt --rm --net=host --env IP=192.168.125.1 docker.io/kipradmin/create3_docker");
myProc->waitForFinished();
output = myProc->readAllStandardOutput();
qDebug() << output;
QObject::connect(&podmanStop, &QProcess::readyReadStandardOutput, [&]()
{
QByteArray data = podmanStop.readAllStandardOutput();
qDebug() << "Output:" << data; });

QObject::connect(&podmanStop, &QProcess::readyReadStandardError, [&]()
{
QByteArray data = podmanStop.readAllStandardError();
qDebug() << "Error:" << data; });

podmanStop.start(podmanStopCommand, podmanStopArgs);

if (v.waitForFinished())
{
qDebug() << "Podman container successfully stopped with exit code:" << podmanStop.exitCode();
}
else
{
qDebug() << "Podman stop failed to start or crashed.";
}

QProcess podmanStart;
QString podmanStartCommand = "sudo podman run";
QStringList podmanStartArgs;
podmanStartArgs << "-dt"
<< "--rm"
<< "--net=host"
<< "--env"
<< "IP=192.168.125.1"
<< "docker.io/kipradmin/create3_docker";

QObject::connect(&podmanStart, &QProcess::readyReadStandardOutput, [&]()
{
QByteArray data = podmanStart.readAllStandardOutput();
qDebug() << "Output:" << data; });

QObject::connect(&podmanStart, &QProcess::readyReadStandardError, [&]()
{
QByteArray data = podmanStart.readAllStandardError();
qDebug() << "Error:" << data; });

podmanStart.start(podmanStartCommand, podmanStartArgs);

if (podmanStart.waitForFinished())
{
qDebug() << "Podman container successfully started with exit code:" << podmanStart.exitCode();
}
else
{
qDebug() << "Podman container failed to start or crashed.";
}
}

void Create3Widget::sensorList()
Expand Down

0 comments on commit 680aaa3

Please sign in to comment.