QT(2)-通过管道关联CMD

1.工程建立

mainwindow.cpp

复制代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTextCodec>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
QString::fromLocal8Bit("中文");
    this->pro = new QProcess;
    this->setWindowFlags(Qt::WindowCloseButtonHint);//设置窗口只有一个关闭按钮
//    Qt::CustomizeWindowHint 标题栏也没有 按钮也没有
//    Qt::WindowTitleHint 窗口只有一个关闭按钮
//    Qt::WindowSystemMenuHint窗口只有一个关闭按钮
//    Qt::WindowCloseButtonHint窗口只有一个关闭按钮
//    Qt::WindowMaximizeButtonHint 最小化按钮不可用,关闭按钮不可用,也就是只有最大化可用
//    Qt::WindowMinimizeButtonHint 还原按钮不可用
//    Qt::SubWindow 窗口没有按钮但是有标题栏
//    Qt::Desktop 没有显示在桌面也没在任务。但是任务管里器里还是有的
//    Qt::SplashScreen 标题栏也没有 按钮也没有在那里出现就站在那里不到,也不能移动和拖到,任务栏右击什么也没有,任务栏窗口名也没有,可以任务栏关闭
//    Qt::ToolTip 选了这个就等死吧......可以试试
//    Qt::Tool 有一个小小的关闭按钮

    QObject::connect(ui->send_edit,SIGNAL(returnPressed()),this,SLOT(on_pushButton_clicked())); //对ui->lineEdit进行信号和槽连接,光标在ui->lineEdit内时按回车键,达到同点击运行按钮一样的效果
    QObject::connect(pro,SIGNAL(readyRead()),this,SLOT(readOutput()));//当准备从进程里读取数据的时候触发输出数据的槽
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    QString cmd = ui->send_edit->toPlainText();
    pro->start(cmd);
    QString out;
    ui->textEdit->setText(out);
}

//从进程中读取数据槽
void MainWindow::readOutput()
{
   // ipconfig
    QTextCodec * codec = QTextCodec::codecForName("gbk");//指定只能读gbk格式的文件
    ui->textEdit->setPlainText(codec->toUnicode(pro->readAll()));
}

mainwindows.h

复制代码
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QProcess>

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_pushButton_clicked();
    void readOutput();//从进程中读取数据槽

private:
    Ui::MainWindow *ui;
    QProcess *pro;//创建一个进程对象
};
#endif // MAINWINDOW_H

UI设计

2.测试

测试dds

相关推荐
用户8055336980312 小时前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner13 小时前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner9 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner10 天前
DicomViewer (目录调整) 2
qt
xcyxiner10 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
LDR00612 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术12 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript