As per the main.cpp which you have sent you have made a class Test and and in the constructor you have gone for making a process with the connection of signal and slots.When an Object t of class test is made the process is initiated and the signal is eminated to be taken in by slot read().To remind you your code is down below:-
#include <QApplication>
#include <QProcess>
#include <QStringList>
#include <QMessageBox>
#include <QtDebug>
{
Q_OBJECT
public:
Test()
{
_proc
->setReadChannelMode
( QProcess::MergedChannels );
connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read() ) );
_proc
->start
( "cjpeg",
QStringList() <<
"aaa" <<
"bbb" );
}
private slots:
void read()
{
QMessageBox::information( 0,
"test", _proc
->readAllStandardOutput
() );
}
private:
};
int main( int argc, char **argv )
{
Test t;
return app.exec();
}
#include "main.moc"
#include <QApplication>
#include <QProcess>
#include <QStringList>
#include <QMessageBox>
#include <QtDebug>
class Test : public QObject
{
Q_OBJECT
public:
Test()
{
_proc = new QProcess( this );
_proc->setReadChannelMode( QProcess::MergedChannels );
connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read() ) );
connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
_proc->start( "cjpeg", QStringList() << "aaa" << "bbb" );
}
private slots:
void read()
{
QMessageBox::information( 0, "test", _proc->readAllStandardOutput() );
}
private:
QProcess *_proc;
};
int main( int argc, char **argv )
{
QApplication app( argc, argv );
Test t;
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
In my existing code I tried the similar thing.First of all I have class steg declared in steg.h but it is public QDialog whereas you have gone for public QObject.Do I have to stick to Public Qobject only.
#ifndef STEG_H
#define STEG_H
#include "ui_stegform1.h"
#include <QProcess>
#include <QMessageBox>
{
Q_OBJECT
public:
{
_proc
->setReadChannelMode
( QProcess::MergedChannels );
connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read()));
// connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
_proc->start(("cjpeg"),s2);
}
private slots:
void stego();
void read()
{
QMessageBox::information( 0,
"stego", _proc
->readAllStandardOutput
());
}
private:
Ui::steg ui;
};
#endif
#ifndef STEG_H
#define STEG_H
#include "ui_stegform1.h"
#include <QProcess>
#include <QMessageBox>
class steg : public QDialog
{
Q_OBJECT
public:
steg(QWidget *parent = 0);
QProcess *_proc;
steg(QStringList s2)
{
_proc = new QProcess( this );
_proc->setReadChannelMode( QProcess::MergedChannels );
connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read()));
// connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
_proc->start(("cjpeg"),s2);
}
private slots:
void stego();
void read()
{
QMessageBox::information( 0, "stego", _proc->readAllStandardOutput());
}
private:
Ui::steg ui;
};
#endif
To copy to clipboard, switch view to plain text mode
Thereafter I overloaded the constructor by passing the Qstringlist s2 ( basically to pass arguments to cjpeg). Thereafter in the function stego() written in steg.cpp I
initiated the object steg t(s2)and called for the function t.read().
void steg::stego() /*** THIS MODULE HIDES CODED.TXT ***/
{
if(QFile::exists("coded.txt")) {
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
steg t (s2);
}
void steg::stego() /*** THIS MODULE HIDES CODED.TXT ***/
{
if(QFile::exists("coded.txt"))
{
QStringList s2;
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
steg t (s2);
}
To copy to clipboard, switch view to plain text mode
I do get the Qmessage box but no message is there
It is blank .You also notice that I pass the signal form "stego" to slot read. Is it OK.
Where is the problem.
Bookmarks