Fedora Linux Support Community & Resources Center
  #1  
Old 23rd June 2007, 01:15 PM
Kimm Offline
Registered User
 
Join Date: Oct 2005
Posts: 2
Connect to output from QProcess? (Qt4)

I'm trying to execute an application from another application (made using Qt4), using QProcess, and then tie into the output of the executed process and display it in a QTextEdit. This is how I am doing it (I'll try to post all relevant code, all of it is a bit much )

mainwindowimpl.h:
Code:
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H

#include "ui_mainwindow.h"
#include <QProcess>

class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
	Q_OBJECT
	public:
		MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
	private slots:
		void Start();
		void Output();
};

#endif
mainwindowimpl.cpp:
Code:
#include "mainwindowimpl.h"
#include <QtGui>

QProcess *app = new QProcess();

MainWindowImpl::MainWindowImpl(QWidget *parent, Qt::WFlags f) : QMainWindow(parent, f)
{
	setupUi(this);
	
	connect(app, SIGNAL(readyReadStandardOutput()), this, SLOT(Output()));
	
	connect(BtnStart, SIGNAL(clicked()), this, SLOT(Start()));
}

void MainWindowImpl::Start()
{
	QString xterm = "thunar";
	QStringList arguments;
	
	arguments<<"/home/kim/";
	
	app->start(xterm, arguments);
}

void MainWindowImpl::Output()
{
	OutText->setText(app->readAllStandardOutput());
}
Now, I can see in the terminal I launch my application from that Thunar prints something about D-Bus to the terminal, but nothing happens with my QTextEdit.

Ideas anyone? I'm kind of a novice with Qt and I've been googling to find an answer for quite a while
Reply With Quote
  #2  
Old 21st March 2012, 03:31 AM
Yalye99 Offline
Registered User
 
Join Date: Mar 2012
Location: China
Posts: 1
windows_xp_2003firefox
Re: Connect to output from QProcess? (Qt4)

can anyone explain it?? thanks ...
using the connect(....,SIGNAL(readyread())....) works on windows...
why mac no??

thks.
Reply With Quote
  #3  
Old 21st March 2012, 05:56 PM
marriedto51 Offline
Registered User
 
Join Date: Jul 2009
Location: England, UK
Posts: 821
linuxfirefox
Re: Connect to output from QProcess? (Qt4)

At a first look, you are doing the right kind of thing to capture output from a command run in a QProcess. But I would not normally expect a GUI application (like Thunar) to write any output to standard output. Presumably what you see in your terminal has been written to standard error instead. If you want to capture both the standard output and standard error, then a cheap way to do that is to use something like
Code:
QProcess::setProcessChannelMode(QProcess::MergedChannels);
(See the documentation at http://http://qt-project.org/doc/qt-4.8/qprocess.html.)
Reply With Quote
Reply

Tags
connect, output, qprocess, qt4

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command display output on console and simultaneously save the command and its output satimis Linux Chat 10 1st August 2008 03:02 AM
output a file to ternimal but keep the output updated Saint Mike Using Fedora 2 30th December 2006 11:22 AM
basic architecture question re : TrollTech Qt QProcess. Skunk Worx Programming & Packaging 2 14th October 2006 10:10 PM
unable to connect to internet,able to connect through windows XP Narasimha Servers & Networking 1 4th October 2005 12:16 AM
unable to connect to internet,able to connect through windows XP Narasimha Servers & Networking 0 3rd October 2005 06:35 PM


Current GMT-time: 12:49 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat