Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. CMD Integration
Forum Updated to NodeBB v4.3 + New Features

CMD Integration

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QT_QT_QTQ Offline
    QT_QT_QTQ Offline
    QT_QT_QT
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why not use what Qt provides already ? e.g. for mkdir your have QDir::mkdir

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      QT_QT_QTQ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why not use what Qt provides already ? e.g. for mkdir your have QDir::mkdir

        QT_QT_QTQ Offline
        QT_QT_QTQ Offline
        QT_QT_QT
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved