Results 1 to 3 of 3

Thread: QProcess with Octave

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Question QProcess with Octave

    I'd like to start QProcess to interact with Octave from within my code.
    I never get any response because the process doesn't seem to be running. I suspect I'm using QProcess wrong.
    Would you be able to help. Here's what I'm doing:

    Qt Code:
    1. #include <QProcess>
    2. #include "octave/oct.h"
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QStringList arguments;
    2. arguments << "--persist";
    3. QProcess octave;
    4. octave.setProcessChannelMode(QProcess::MergedChannels);
    5. octave.start("/usr/bin/octave3.2", arguments);
    6.  
    7. if (octave.state() == QProcess::Running)
    8. {
    9.  
    10. QString command = "1+2\n";
    11. octave.write(command.toAscii());
    12.  
    13. QString answer; answer.append(octave.readAll() + "\n");
    14. cout << "answer: " << command.toLocal8Bit().constData() << "\n";
    15.  
    16. }
    17.  
    18. octave.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by timmu; 15th October 2012 at 12:22.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess with Octave

    You assume that as soon as you write [11] Octave has read the command, processed it and returned a value before you try to read [13] i.e. you assume write is blocking. It cannot be blocking because it does not have any notion of what constitutes "finished" behaviour on the part of the controlled process. You need to either handle output as it is generated and announced by the QProcess object using a readyRead() signal, or use QIODevice::waitForReadyRead(). Be aware that the expected output may not arrive in one chunk.

    Since you want to use Octave by using the "octave" process you should not need any includes from Octave.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess with Octave

    Quote Originally Posted by ChrisW67 View Post
    i.e. you assume write is blocking.
    ...or that readAll() is blocking (and is going to return all data in one chunk).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Want to run Octave m-file
    By Tottish in forum Newbie
    Replies: 14
    Last Post: 28th December 2012, 16:22
  2. Replies: 0
    Last Post: 26th August 2010, 10:44
  3. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39
  4. QProcess
    By bashamehboob in forum Qt Programming
    Replies: 3
    Last Post: 31st March 2008, 15:21
  5. QProcess again ..
    By cmeliak in forum Qt Programming
    Replies: 13
    Last Post: 24th May 2006, 20:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.