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. [SOLVED] Can`t send data to QProcess

[SOLVED] Can`t send data to QProcess

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    MiloserdOFF
    wrote on last edited by
    #1

    Im trying to create an app, which can compile and run some simple cpp progs, so I need to write an output to textEdit and read input from lineEdit. The code below compiles, but the data isnt sending to the process corectly (nothing happends).
    @void MainWindow::on_lineEdit_returnPressed()// input from lineEdit
    {
    ui->textEdit->insertPlainText(ui->lineEdit->text()+"\n");
    cp->write(ui->lineEdit->text().toStdString().c_str());
    ui->lineEdit->clear();
    }
    void MainWindow::on_action_24_triggered()
    {
    // The code below compiles and runs the prog from textEdit
    QString str = tabs[cur_tab]->toPlainText();
    QFile("temp.cpp").remove();
    QFile file("temp.cpp");
    file.open(QIODevice::Append | QIODevice::Text);
    QTextStream out(&file);
    out << str;
    out << "\n";
    file.close();
    cp->start(("g++ temp.cpp"));
    cp->waitForFinished();
    if (!QFile::exists("a.exe"))
    {
    qDebug() << "Error";
    ui->textEdit->append(cpError);
    }
    else
    {
    cp->start("a.exe");
    //Another trouble here
    //cp->waitForFinished(); //<-If not commented then the programm crashes
    //QFile("a.exe").remove(); // And the file cant be removed, because is still running } }@ The main problem is that the data cant reach the process, I dont know why. Therere no warns or errors that are displayed.
    P.S. Sorry for my english!http://postimage.org/image/4sk3ru0wh/(Screenshot of my UI)!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      liuyanghejerry
      wrote on last edited by
      #2

      Though not look into it, I think you may want to try QProcess::readAllStandardOutput() or QProcess::readAllStandardError() for details.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MiloserdOFF
        wrote on last edited by
        #3

        The problem has been solved - you need to send "\n" at the end of input.

        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