Untitled
unknown
python
a year ago
1.5 kB
14
Indexable
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, process(new QProcess(this))
{
ui->setupUi(this);
// Correctly reference the button with the name from your .ui file
connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::on_runButton_clicked);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_runButton_clicked()
{
// Path to the external executable
QString executablePath = "C:/Users/RD3/Downloads/Py2EXE.exe";
// Start the executable
process->start(executablePath);
// Check if the process started successfully
if (!process->waitForStarted())
{
QMessageBox::critical(this, "Error", "Failed to start the external program.");
}
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QProcess> // Include QProcess for running executables
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_runButton_clicked();
private:
Ui::MainWindow *ui;
QProcess *process; // QProcess instance for managing the external executable
};
#endif // MAINWINDOW_H
Editor is loading...
Leave a Comment