我正在制作一个在Windows上在Qt Creator中添加新用户帐户的应用程序。应用程序要求输入用户名和密码,然后打开cmd并输入命令net user username password / all。我希望能够创建一个总是等于cmd在输入命令后返回的标签,例如“此帐户已存在”。我的代码如下。
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QProcess"
#include "QTextStream"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QProcess process1;
QStringList arguments1;
arguments1 << "net user" << ui->lineEdit->text() << ui->lineEdit_2->text() << "/add";
QString path = "C:/Windows/system32/WindowsPowerShell/v1.0/powershell.exe";
process1.execute(path, arguments1);
QString output(process1.readAllStandardOutput());
ui->label_4->setText(output);
}
答案 0 :(得分:0)
process1.QProcess::waitForFinished(-1);
QString output(process1.readAllStandardOutput());
ui->label_4->setText(output);