-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc_console.cpp
More file actions
64 lines (50 loc) · 1.46 KB
/
src_console.cpp
File metadata and controls
64 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <QProcess> // Need this for the console function
#include <QTimer>
#include "src_console.h"
#include "ui_src_console.h"
src_console::src_console(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::src_console)
{
ui->setupUi(this);
}
src_console::~src_console()
{
delete ui;
}
void src_console::on_consoleInput_returnPressed()
{
QString input = ui->consoleInput->text();
if (input.isEmpty()) return;
if (input == "clear" || input == "clr") {
ui->console->clear();
ui->consoleInput->clear();
return;
}
std::cout << "Input received" << std::endl;
ui->consoleInput->clear();
ui->console->append(input);
ui->consoleInput->clear();
QTimer::singleShot(150, this, [=] {
QProcess process;
#ifdef Q_OS_WIN
process.start("cmd.exe", QStringList() << "/c" << input);
#else
process.start("bash", QStringList() << "-c" << input);
#endif
process.waitForFinished(); // Wait until command finishes
QString output = QString::fromLocal8Bit(process.readAllStandardOutput());
QString error = QString::fromLocal8Bit(process.readAllStandardError());
if (!output.isEmpty())
ui->console->append(output);
if (!error.isEmpty())
ui->console->append(error);
});
}
void src_console::on_pushButton_3_clicked()
{
if (!ui->consoleInput->text().isEmpty()) {
on_consoleInput_returnPressed();
}
}