Results 1 to 14 of 14

Thread: Need help!!!!! Problem in running a program with the help of QProcess

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2013
    Posts
    46
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    6

    Default Need help!!!!! Problem in running a program with the help of QProcess

    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.

    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("out.txt");
    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()
    }

    In an attached file output.png Enter two numbers is not written. As i know i have to enter two numbers then i entered 2 3 but out.txt contain the whole program output like:
    Enter two numbers 2 3

    But problem is with console window.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Need help!!!!! Problem in running a program with the help of QProcess

    This continued opening of the same thread over and over again it really getting annoying.
    It means one of the admins has to search for the duplicate and manually merge the thread.

    Quote Originally Posted by parulkalra14 View Post
    When i compiled this program a batch file will open that does not contain Enter two numbers statement
    When you compile a program then it is not executed.
    Building and running are two very different operations.


    Quote Originally Posted by parulkalra14 View Post
    Code is :
    For the love of $DETIY use code tags.

    Quote Originally Posted by parulkalra14 View Post
    Qt Code:
    1. QProcess *proc = new QProcess(this);
    2. proc->startDetached(program);
    3.  
    4. if(proc->NotRunning)
    5. msgBox.setText(st);
    6. msgBox.exec();
    7. proc->waitForFinished();
    To copy to clipboard, switch view to plain text mode 
    That does not make any sense at all.

    QProcess::startDetached() is a static method, "proc" will be totally unaffected.

    NotRunning is a state enum value, not a public variable. That condition is always false (NotRunning == 0).

    The message box should probably not always be executed.

    Cheers,
    _

Similar Threads

  1. QProcess Problem: Program doesnt start
    By musaulker in forum Newbie
    Replies: 5
    Last Post: 30th April 2020, 23:07
  2. Replies: 0
    Last Post: 26th August 2010, 10:44
  3. Replies: 3
    Last Post: 7th August 2010, 15:12
  4. QProcess problem (Main program hangs)
    By sincnarf in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2007, 09:26
  5. Replies: 1
    Last Post: 17th May 2006, 00:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.