I've created a simple app in QT Creator 4.2.0, i.e., QT Widgets Application, used all defaults. Added one button. I've tried to mimic multiple posts I've found around web, but can not get a python script to launch correctly. I keep getting this message:
QProcess: Destroyed while process ("python.exe") is still running.
Python.exe is added to Path variable.
What I would like to happen is, when the button is pressed, launch the python script, and then wait some amount of time (but don't lock up the GUI), then terminate python script.
I apologize, I'm very new to c++/QT.
My QT code is below:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QDir>
#include <QCoreApplication>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
//define file paths.. make sure the paths work
QDir dir1("C:/SFI/FastScan/Calibration/");
QFile file1("C:/SFI/FastScan/Calibration/pytest.py");
QString script1 = "C:/SFI/FastScan/Calibration/pytest.py";
QFile file2(script1);
qDebug() << dir1.exists() << file1.exists() << file2.exists();
// these all result in true, true true
// latest method I tried
QString command("python.exe");
QStringList args;
args << script1;
QProcess *myProcess = new QProcess(this);
myProcess->start(command,args);
}
The python script is below, python 2.7 ...
#!/usr/bin/env python
import time
while True:
time.sleep(1)
print time.time()
Edit: I kept at it, by replacing the last 5 lines of my QT code with these two lines I can launch my python script,
QProcess *myProcess = new QProcess();
myProcess->startDetached("python.exe C:/SFI/FastScan/Calibration/pytest.py" );
I've tried to use the myProcess.terminate()
, but can not get the script to exit.