CMD Integration
-
My program will be integrating with command prompt.
***mainwindow.cpp*** #include "mainwindow.h" #include "ui_mainwindow.h" #include <QByteArray> #include <QProcess> #include <Windows.h> #include <iostream> #include <string> #include <cstdlib> #include <stdlib.h> using namespace std; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { /* QProcess process(this); process.startDetached("ipconfig"); process.waitForFinished(); */ }
***main.cpp*** #include "mainwindow.h" #include <QApplication> #include <iostream> #include <Windows.h> #include <string> #include <QByteArray> #include <QProcess> #include <cstdlib> #include <stdlib.h> using namespace std; bool check = false; int main(int argc, char *argv[]) {QApplication a(argc,argv); MainWindow w; w.show(); QProcess process; process.startDetached("cmd"); process.waitForFinished(); return a.exec(); }
Above codes will "call out" the GUI window and command prompt at the same time. Now, lets assume , there is a push button in the GUI window. and there is a string that included within the push button . So when the end-user click the push button , the push button will parse the string into cmd. Example: I set this text "mkdir myFolder" to the push button , after that, the push button will parse or "send" this string "mkdir myProject" into cmd. Anyone here know what is the best way to approach this kind of problem. Thank you in advance!
-
Hi,
Why not use what Qt provides already ? e.g. for mkdir your have QDir::mkdir
-
@SGaist
Greetings,Good idea though ! " Regarding to this string "mkdir myFolder" , i was just providing an example in order to clarify my statements . The string could be anything, the idea is how to parse the string into cmd . Right now, i am able to "call out" two windows which i mentioned earlier, the moment the user press push button, we also can see the same string in command prompt . I sincerely hope that you will give me idea on this approach . thank you
-
You can use QProcess and build commands that you call when you want. However note that not all commands are separated executables, some are shell built-in which cannot be invoked in the same manner as other commands.