开发者

using qt : How To Build a Gui OnTop Of a Console Application?

i have a console application that ge开发者_如何学JAVAnerated 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 .


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).


from http://www.qtcentre.org/threads/33506-where-is-cout-in-Qt-Creator

first add

CONFIG   += console 

to your .pro file

second use

#include <stdio.h>

  QTextStream out(stdout);
  out << QString("Some text");

For me it works this way.

Have fun


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.


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

\# Application template<br>
TEMPLATE = app

\# QMake configuration<br>
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 !


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜