<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>open-nandra &#187; gui</title>
	<atom:link href="http://open-nandra.com/tag/gui/feed/" rel="self" type="application/rss+xml" />
	<link>http://open-nandra.com</link>
	<description>open source</description>
	<lastBuildDate>Thu, 09 Sep 2010 11:28:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to control console application in Qt.</title>
		<link>http://open-nandra.com/2009/06/how-to-control-console-application-in-qt/</link>
		<comments>http://open-nandra.com/2009/06/how-to-control-console-application-in-qt/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 13:38:16 +0000</pubDate>
		<dc:creator>Marek Belisko</dc:creator>
				<category><![CDATA[HOW-TOs]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[QProcess]]></category>

		<guid isPermaLink="false">http://open-nandra.com/?p=251</guid>
		<description><![CDATA[For liqrf project we would like to add some gui so I start thinking about possibility to have controlled existing liqrf console appliaction via some nice gui (be honest not all users like command line ). In this how to I&#8217;ll try to show how easily use Qprocess class for this purpose. For Qt development [...]]]></description>
			<content:encoded><![CDATA[<p>For liqrf project we would like to add some gui so I start thinking about possibility to have controlled existing liqrf console appliaction via some nice gui (be honest not all users like command line <img src='http://open-nandra.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). In this how to I&#8217;ll try to show how easily use Qprocess class for this purpose.</p>
<p><span id="more-251"></span></p>
<p>For Qt development I&#8217;m using Qt Creator which is freely available and combine designer and editor to one complex program.</p>
<p>First simple program which print some data to standard output.</p>
<pre>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;

int main(void)
{
    unsigned i = 0;

    for ( ; ; ) {
        fprintf(stdout,"Value = %X\n", i++);
        fflush(stdout);
        sleep(2);
    }
    return 0;
}</pre>
<p>For compiling use :</p>
<pre>gcc -o test test.c</pre>
<p>For reading stdout we use Qt signal <strong>readyStandardOutput()</strong> which is triggered when something is written to stdout.</p>
<p>In Qt Creator just create default Qt4 application.</p>
<p>Add to mainwindow.h:</p>
<pre>private:
    Ui::MainWindowClass *ui;
    QProcess *process;</pre>
<p>Methods and slot in mainwindow.cpp:</p>
<pre>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include &lt;QProcess&gt;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindowClass)
{
    ui-&gt;setupUi(this);
    process = new QProcess(this);
    process-&gt;setReadChannel(QProcess::StandardOutput);
    connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(updateOutput()));
    process-&gt;start("./test");

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow :: updateOutput(void)
{
    QByteArray bytes = process-&gt;readAllStandardOutput();
    ui-&gt;textEdit-&gt;insertPlainText(bytes);
}</pre>
<p>Thats all. When you run Qt application you should see all stdout in textEdit.</p>
<p style="margin: 0px; text-indent: 0px;"><!--StartFragment--><!--StartFragment-->Marek</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px;"><!-- p, li { white-space: pre-wrap; } --></div>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 14px; width: 1px; height: 1px;"><!-- p, li { white-space: pre-wrap; } --></div>
]]></content:encoded>
			<wfw:commentRss>http://open-nandra.com/2009/06/how-to-control-console-application-in-qt/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
