Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. Problem in Using QProcess
Qt 6.11 is out! See what's new in the release blog

Problem in Using QProcess

Scheduled Pinned Locked Moved India
2 Posts 1 Posters 1.8k 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.
  • P Offline
    P Offline
    parulkalra14
    wrote on last edited by
    #1

    First of all I make a file which reads program written on plainTextEdit and batch file for output and i am able to reterive the output from batch file and display it to another plainTextEdit but problem arises in case of cin and scanf statements .For example :

    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cout<<"Enter two numbers";
    cin>>a>>b;
    return 0;
    }
    When i compiled this program a batch file will open that does not contain Enter two numbers statement that means it can take the input only but does show cout/printf statements,that is creating problem because user will not be able to detect what to enter. As i understands the problem and know what to enter in a batch file suppose i enetered 2 3 so output reterive to a plainTextEdit is correct i.e Enter two numbers 2 3. But problem occurs at User Console/Command Prompt.

    The Code is:
    bool MainWindow::run_file()
    {
    QMessageBox msgBox;
    QString program = "cons.bat";
    QString st="PRESS OKK!!";
    QStringList arguments;
    QProcess *proc = new QProcess(this);
    proc->startDetached(program);

    if(proc->NotRunning)
    

    msgBox.setText(st);
    msgBox.exec();
    proc->waitForFinished();

    display_output();
    return(true);
    

    }
    void MainWindow::display_output()
    {

    QFile file&#40;"out.txt"&#41;;
    if(!file.open(QIODevice::ReadOnly)) {
            QMessageBox::information(0, "error", file.errorString());
       }
    //QTextStream str(&file);
    
    QString out_str;
    
    while (!file.atEnd())
    {
        out_str=file.readAll();
    }
    ui->plainTextEdit_3->clear();
    ui->plainTextEdit_3->insertPlainText(out_str);
    file.remove();
    

    }

    How to use flush in my code? I want everytime cout/printf occurs output statement appears in or flush to console window? Need Help!!!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      parulkalra14
      wrote on last edited by
      #2

      Flush is a right way to use in my problem?? Somebody please tell me something ?

      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