views:

739

answers:

4

i have a console application that generated from bison (a parser) and i want to build a simple gui for it so i can send input from this gui to the console and get output from the console into the gui . i tried to do that using java process class but it doesnt work for me , please help me to do that using qt .

+1  A: 

Hey,

I think you have to put the following entries in your .PRO file :

# Application template
TEMPLATE = app

# QMake configuration
CONFIG += console

You can then create a Window in Qt, and you'll have your main window next to a console !

Example :

main.cpp
{
    QApplication App(argc, argv);
    ...
    MainFrm* pMainFrm = new MainFrm();
    pMainFrm->show();
    ...
    int ExitCode = App.exec();
    return ExitCode;
}

Hope it helps a bit !

Andy M
but how can i send input and get output ?!!!!
radi
+2  A: 

It depends on the complexity of the data you want to feed in/out of your console application.

Low complexity Use some command switches that you pass from your Qt GUI to your console application. Look at the QProcess class documentation.

High complexity I would go with an RPC-like solution. Look at the QtDBus documentation (Linux/Unix only).

Note: I made the assumption that you want to keep your generated bison parser apart from your Qt GUI (in case you need the regenerate it again).

esavard
rasjani
hahaha, right. :) But it could be a pain to parse if your console application output a lot of info to sdtout. Hence my two fold response : Low vs High complexity. ;)
esavard
A: 

An alternative: Tcl/TK

Unless you have good reason to use QT you might find it easier to use Tcl/Tk. Tcl was designed from the ground up for wrapping scripting and GUI facilities around existing C programs and is by far the easiest way to do this. It supports quite a few different ways to integrate C code and Tk (the GUI toolkit shipped with Tcl/Tk) is quite concise to program and very simple to learn (think: one 2 hour lab in a CS paper).

Tcl integration features:

  • Tcl can open a full-duplex pipe to the program and communicate down the pipe. At a guess this is probably the best option for you.

  • You can use fork/exec to run the program, passing command line arguments.

  • You can also embed the Tcl interpreter in your C program; the API for doing this is dead simple.

  • Tcl has API's (also quite simple) for extending the interpreter with new commands.

  • Probably one or two other ways that I can't remember off the top of my head.

ConcernedOfTunbridgeWells
+1  A: 

Keep your console and your graphical application, two separated applications. You already have the console one, so let's see how to make the other:

Make a normal GUI application in Qt and, using the QProcess class, call your console application. Use the readData() and writeData() (and similar) methods of this class to read from standard output and write to standard input of your console application.

Check the QProcess documentation for details.

Silas