PDA

View Full Version : simple hello world question



chap19150
12th June 2006, 14:54
If i have a cpp program that prints hello world to standard output,
how do i put a gui on top of this standalone program? For example
a button that runs the cpp hello world program...

jacek
12th June 2006, 14:55
You can use QProcess for this.

patrik08
12th June 2006, 15:04
If i have a cpp program that prints hello world to standard output,
.

This sample snipp search if window is online and ethernet work...

the output from # ipconfig /all

and process.readAll(); grab result....



bool DB_Setup::TestGigaByte()
{
#if defined Q_WS_WIN
bool onlinestatus;
QString status; /* find Address to check if the gay is online! why? webdav disk stay on cache lifetime! :-( */
QProcess process;
process.setReadChannelMode(QProcess::MergedChannel s);
process.start("ipconfig" , QStringList() << "/all");
if (!process.waitForFinished()) {
status = process.errorString();
} else {
status = process.readAll();
}
onlinestatus = status.contains("address", Qt::CaseInsensitive);
if (onlinestatus) {
/*qDebug() << "### yes ethernet TestGigaByte " << onlinestatus;*/
} else {
/*qDebug() << "### no ethernet TestGigaByte " << onlinestatus; */
}
return onlinestatus;
#endif
return WebDavCheck(); /* other OS only check if the remote config file exist */
}

chap19150
12th June 2006, 15:07
ok, i think i understand QProcess but what if I want the programs to compile together
on one makefile?

jacek
12th June 2006, 15:27
ok, i think i understand QProcess but what if I want the programs to compile together
on one makefile?
But do you want two separate executables?

Makefiles for Qt programs are a bit complex, so you use qmake or some other tool to generate them. qmake can't create a single Makefile for two executables, but you can place those programs in separate directories and use a .pro file with TEMPLATE="subdirs" --- this way qmake will generate a Makefile that will run Makefiles from subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").

patrik08
12th June 2006, 15:28
ok, i think i understand QProcess but what if I want the programs to compile together
on one makefile?

If You like external programm must go inside qt.....
make a static lib from the programm ...
and on your header .... link the programm original header...
.... and call the function easy from qt ....

rewrite cout << to

sprintf (buffer, "%s%s", one , dwo);
return buffer;

Sample static libs programm...
http://ciz.ch/svnciz/_STATIC_LIBS_QT4/lib_tidy_src/
have a look on
http://ciz.ch/svnciz/_STATIC_LIBS_QT4/lib_tidy_src/lib_tidy_src.pro

Qmake can compile a lot of programm ... put source on a dir...

cd dir .... qmake -project && qmake && make
Grab error and clean the code...
*** pro file LANGUAGE = C++ or LANGUAGE = C
if the code is ok ... remove main.cpp and transform to static libs... and call function from qt....

patrik08
12th June 2006, 15:42
subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").

As sample:



TEMPLATE = subdirs

SUBDIRS = lib_sqlite_qt4 \
date_qdialog \
lib_tidy_src \
lib_wgetqt_src \
src_0


dir structure .....
http://ciz.ch/svnciz/_STATIC_LIBS_QT4/

compile on mac , linux , window .
1- staticlibs from sqlite3
2- qdate libs calendar designer plug-in as static libs...
3- tidy libs to clean html bad & holocaust QTexEdit html
4- wget libs & network & smtp auth funktion
5- Final build the programm main.cpp included all libs.... the result one exe win or **.apps mac....

jacek
12th June 2006, 15:58
rewrite cout << to

sprintf (buffer, "%s%s", one , dwo);
return buffer;
Better use QString and QTextStream instead.

chap19150
12th June 2006, 19:47
But do you want two separate executables?

Makefiles for Qt programs are a bit complex, so you use qmake or some other tool to generate them. qmake can't create a single Makefile for two executables, but you can place those programs in separate directories and use a .pro file with TEMPLATE="subdirs" --- this way qmake will generate a Makefile that will run Makefiles from subdirectories (in other words you will have more than one Makefile, but you will be able to compile all programs with a single "make").

ok, I have 2 directories /files/helloworld and /files/qtgui
I have a makefile for the helloworld program. do I also
have to put a .pro file in the helloworld directory also, and if
so what would this contain?

jacek
12th June 2006, 20:40
do I also have to put a .pro file in the helloworld directory also, and if so what would this contain?
No, you don't have to, but you need a .pro file in /files directory.

Something like:
TEMPLATE = subdirs
SUBDIRS += ./helloworld ./qtgui

chap19150
21st June 2006, 16:00
ok so it seems that i need one executable. Essentially what I have
is a full featured program that I need to put a gui on top of. The gui
will call functions from the main program. I wanted to
start with the hello world program just to see how it is done.

any advice?

jacek
21st June 2006, 17:31
ok so it seems that i need one executable. Essentially what I have
is a full featured program that I need to put a gui on top of.
If you want one executable, it means that you want a single program. Everything depends on the size of the original application and its design. If you can bypass its I/O routines, all you have to do is to implement their equivalents in Qt. If not, most likely you will have to implement screen scraping and for this you could try freopen() and pipe() (to intercept stdin, stdout and stderr).

atm
11th July 2006, 20:42
I was just doing this last week. Here's what I did:
Make a cpp file that looks like this:

#include <QApplication>
#include "mainimpl.h"


using namespace std;

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

mainImpl window;

return app.exec();
}

This creates a QT application and loads my class, mainImpl. mainImpl is an implementation of a form that I created. I'll now show an important part of mainImpl:
the .cpp file:

mainImpl::mainImpl(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);
this->show();

//some sample things that my program needs
fillArray(geneNames);
numLineGenes = 0;
numExps = 0;

//signal/slot for the exit button in the menu
connect(ui.actionExit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
}

and the .h file:

#include "ui_FormV4a.h"

class mainImpl: public QMainWindow {

Q_OBJECT

public:
mainImpl(QWidget *parent = 0);

~mainImpl();
private:
Ui::FrmReformatData ui;
}

You can then put all your subroutines from your original program into the mainImpl class. To use a button to run the subroutines, you need to use slots and signals. There are lots of things online that explain slots and signals.

Hope that helped answer your question.