Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-13-2005, 08:50 AM   #1
LQ Newbie
Registered: May 2005
Posts: 16

Rep: Reputation: 0
running a program from within QT

i was tryign to make a gui in fortran, realized that's way too mcuh work and pain in the ass, so the easiest way seems to be make a interface to get the paramaters, output to file then run the program with the input from file. i got the output to file from the program fine, now all i gotta do is run the fortran program. so the question is, how do i run a program or a bash script from QT?

the QT program i have now is basicly a form and when i type in the info, i press a button everythign goes to a text file. what i want is to be able to press a button and have it run the fortran program that reads the data file in the background. that program would output to a file, then when the fortran program is done running, the gui program reads the output file then print it on the screen.

Old 06-14-2005, 01:10 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
I don't think QT provides a method to run an external command. But that's OK because QT uses C++, so you can just use the system() function. See
man 3 system
You will need to include the stdlib.h header in the file you want to call system() from.
Then just do:
int rtn = system(command)
where command is a regular string (i.e. double-quoted or NULL-terminated; you can also use a QString here by passing the return value of its latin1() method). The string should contain the command to run, exactly as you would type it in at your shell's command line. See
man bash
for details on how to cope with command-line arguments and unusual characters.

After running this, the value of rtn will hold the return value of the command, assuming the command ran successfully.
Old 06-14-2005, 01:13 PM   #3
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
how do i run a program or a bash script from QT?
I don't know QT, but I've heard the name qtProcess (or similar) and figured...

You might also want to use your programming language's built-in interface to the shell;
in C and C++, that's `system', in python it's `os.system', for *, well GIYF

hth --Jonas
Old 06-14-2005, 04:45 PM   #4
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
Originally posted by jonaskoelker
GIYF is also your friend :)
Old 06-14-2005, 05:08 PM   #5
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Could you write the fortran program as a filter and have a bash or tcl wrapper piece everything together?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a program LinAck Linux - Newbie 1 07-02-2005 02:17 AM
Running a program rj686 Linux - Software 16 10-10-2004 07:19 PM
need help running a program boogerman Linux - Software 8 11-24-2003 02:17 PM
Running a new program bananaman Linux - Newbie 4 04-08-2003 04:00 PM
Running a C program isaacais Linux - Newbie 3 12-11-2002 02:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration