Qt进程间调用.exe可执行文件

Qt 使用 QProcess 类完成进程间交互,打开股票交易软件,示例如下:

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
#include <QtGui>
#include <QPushButton>
namespace Ui {
    
    
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
    
    
    Q_OBJECT
 
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
 
private slots:
    void openProcess();
    void readResult(int exitCode);
 
private:
    QProcess *p;
};
 
#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    
    
    p =new QProcess(this);
    QPushButton *bt = new QPushButton("execute notepad", this);
    connect(bt,SIGNAL(clicked()),this,SLOT(openProcess()));
}
 
MainWindow::~MainWindow()
{
    
    
 
}
void MainWindow::openProcess()
{
    
    
    p->start("Tc.exe", QStringList() << "E:\\Test\\Notepad.exe" << "dir");

猜你喜欢

转载自blog.csdn.net/qq_45662588/article/details/120567526