Results 1 to 6 of 6

Thread: Using system() with gnuplot in qt

  1. #1
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Using system() with gnuplot in qt

    Hi all I am trying to use system() with gnu plot.

    I have some code which looks like this:

    Qt Code:
    1. system("gnuplot");
    2. system("set term jpeg");
    3. //...more code here
    4. system("exit");
    To copy to clipboard, switch view to plain text mode 

    However all it does it run the first system call and then stops with the command prompt window open. You close this command prompt window and it then calls the next system call, which of course errors because it is not aware of the former command. I was wondering how i get around this problem. Any help would be much appreciated.

    I've tried using qwt before you say anything, and lets just say it caused me a lot of problem, doesn't offer the functionality i require and seems far harder to use. Therefore I'm sticking with gnuplot.

    I'm using windows 7, Home Premium 32 bit.

    Thanks for your time and trouble.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using system() with gnuplot in qt

    Read about using QProcess.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using system() with gnuplot in qt

    Every system call launches a new shubshell and runs the provided command in that shell. If you want to use system() in this way, you'll have to combine your shell commands into one, something like:

    Qt Code:
    1. string cmd = "gnuplot; set term jpeg; ... ;exit";
    2. system(cmd);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Using system() with gnuplot in qt

    You can also use popen() if you want to stick to plain C. I think that's closer to what you want to achieve.
    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.


  5. #5
    Join Date
    Oct 2010
    Posts
    54
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Using system() with gnuplot in qt

    How would I go about using this popen() function?

    Thanks

  6. #6
    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: Using system() with gnuplot in qt

    I can see three options:
    • Write your gnuplot commands to a temporary file and execute:
      Qt Code:
      1. system("gnuplot <tempfilename");
      To copy to clipboard, switch view to plain text mode 
      You can use mkstemp (3) or QTemporaryFile to get a safe temporary file.
    • Open gnuplot using QProcess and write your gnuplot commands to the sub-process input stream that QProcess provides.
    • popen (3) gnuplot and use the FILE handle returned to write your gnuplot commands before pclose (3)

Similar Threads

  1. coordinate system
    By Wojtek.wk in forum Newbie
    Replies: 7
    Last Post: 12th April 2010, 13:47
  2. Getting System Information
    By Ankitha Varsha in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2008, 10:37
  3. The coordinate system
    By avis_phoenix in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2008, 12:16
  4. system in Qt
    By jaca in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2008, 15:56
  5. Running QT3 and QT4 on the same system?
    By milonguero in forum Installation and Deployment
    Replies: 2
    Last Post: 26th April 2007, 18:38

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.