PDA

View Full Version : How To Redirect The Console Output To A Text Browser/pop Up



deekayt
30th October 2006, 16:43
I am running an external process ( dos exe file runnable on command prompt) through Q process
I need to capture the error messages and either display them in the text browser ( which is static in my form) or make custom made message (depending on what the exe program has given ) and then display them in the textbrowser/popUP

Earlier I was able to do so in qt3.3.4 on linux with the following code


system ( "/root/stego/encrypt.sh >& /root/stego/error.txt" );
textBrowser->clear();
textBrowser->setSource( "/root/stego/error.txt") ;

where I was running the command prompt command through a script file ( encrypt.sh in above case) and redirecting the screen output to error .txt and then redirecting it to text browser.

Now in qt 4 ( windows) I am using the Qprocess as under


void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
QStringList s3;
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
QProcess::startDetached( QString("burp.exe"),s3 );

}
The burp.exe is command prompt command and gives the ok/error messages on the screen ( on console). How to direct the same to a text file.Then compare and show a custom message say in a text browser or I can even resort to pop message( why not?/let me improve with qt 4)

Thanks in advance for the guidance.

jacek
30th October 2006, 21:02
You can use QProcess::readAllStandardOutput() and QProcess::readAllStandardError() to read the data. QProcess::readyReadStandardError() and QProcess::readyReadStandardOutput () signals will be emitted when the data is available.

Of course you will have to use QProcess instance, instead of QProcess::startDetached().

deekayt
31st October 2006, 17:31
I have tried the following


void steg::encrypt()
{
QProcess *P =new QProcess ;
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
QStringList s3;
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P->startDetached( QString("burp.exe"),s3 );
QString result_all = P->readAllStandardOutput();
//QMessageBox::about(this, tr("JPSTEGO"),tr(result_all.toAscii()));


QFile file;

file.setFileName("showjpegfile.txt");
file.open(QIODevice::WriteOnly);

QTextStream out(&file);
out << result_all.toAscii();

ui.textEdit->insertPlainText(result_all);

}

First I tried to take the Qstring and display in the message box. Nothing happened . Message box comes up but no message is there. Though burp .exe gets executed and gives msg everytime on the command prompt.
Then I tried to redirect the console output to a file and put in a textedit( not a clean way)but it also didnot work.

I am only sure that burp.exe gets executed sinceI find files encrypted as required.I am also sure that some console output always comes. But after that I am not able to find out the problem.

jacek
31st October 2006, 19:29
P->startDetached( QString("burp.exe"),s3 );
QString result_all = P->readAllStandardOutput();
I've already told you two times, that QProcess::startDetached() is a static method. There is no sense in invoking it on an object.

Try:
P->start( "burp.exe", s3 );
P->waitForFinished();
QString result_all = P->readAllStandardOutput();
and make sure that this "burp" thing writes to standard output, not standard error stream.

deekayt
2nd November 2006, 10:52
My requirement is to get the console output to the text browser.( Message box and text edit)
I have tried the following code


void steg::encrypt()
{
QProcess *P =new QProcess ;
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
QStringList s3;
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P->start( QString("burp.exe"),s3 );
P->waitForFinished();
QString result_all= P->readAllStandardOutput();
ui.textBrowser->setSource( result_all);
}
But it did not work . Then I tried to write the Qstring result_all to a file and then see the file manually.The file gets created but nothing is written to file. That means nothing is in QString result_ all . Then I tried to see that the Qstring result_all is put in the tetxEdit ( since setText is there and perhaps Url thing might be giving problem in TextBrowser) But that also did not work. Those codes are down below



QFile file;
file.setFileName("showjpegfile.txt");
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out << result_all; //NOTHING HAPPENED

ui.textEdit->textCursor().insertText(result_all); //NOTHING HAPPENED
How can I try to put in the message box
I tried the code below.But it doesnot work.



QMessageBox::about(this, tr("About JPSTEGO"),
tr("<p>The <b>JPSTEGO</b> is a data hiding and extraction software"
"forhiding data while converting image files to JPEG format",
+result_all));

jacek
2nd November 2006, 19:45
Does P->waitForFinished() return true? Does "burb.exe" write data to standard output?

deekayt
3rd November 2006, 16:52
While I was awaiting your reply I tinkered with the code and was able to figure out the error.
In fact burp.exe was writing to standard error channel instead of standard output. I then further improved it to merge the channels and the code is as
below


void steg::encrypt()
{
QProcess *P =new QProcess ;
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
QStringList s3;
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P->setReadChannelMode(QProcess::MergedChannels);
P->start( QString("burp.exe"),s3 );
P->waitForFinished();
QString result_all= P->readAllStandardOutput();
QFile file;
//QDir::setCurrent("E:");
file.setFileName("encrypt_error.html");
file.open(QIODevice::WriteOnly);

QTextStream out(&file);
out << result_all;
file.close();
ui.textBrowser->clear();
QUrl myurl1;
myurl1=QUrl::fromLocalFile( "encrypt_error.html" ) ;
ui.textBrowser->setSource(myurl1);

}
1. Now I am able to get whatever is the output to the textBrowser . But I believe there would be better way without getting through the file thing. Could you suggest a better method.

2. Moreover I want to output to textbrowser the messages defined by me after comparing what is the output of these exe processes. Is there a method in QT to compare the message, or look for a string and then make own message or delete a part of the message or append a part from the user side and then get it to the textbrowser.

jacek
3rd November 2006, 17:19
Now I am able to get whatever is the output to the textBrowser . But I believe there would be better way without getting through the file thing. Could you suggest a better method.
QTextEdit::setPlainText() or QTextEdit::setHtml() (http://doc.trolltech.com/4.2/qtextedit.html#html-prop)


Moreover I want to output to textbrowser the messages defined by me after comparing what is the output of these exe processes. Is there a method in QT to compare the message, or look for a string and then make own message or delete a part of the message or append a part from the user side and then get it to the textbrowser.
QRegExp and QString::find()

deekayt
4th November 2006, 14:39
Now I am facing a peculiar problem .
After resolving the issue of burp.exe with the following code

void steg::encrypt()
{
QProcess *P =new QProcess ;
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
QStringList s3;
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P->setReadChannelMode(QProcess::MergedChannels);
P->start( QString("burp.exe"),s3 );
P->waitForFinished();
QString result_all= P->readAllStandardOutput();
QFile file;
//QDir::setCurrent("E:");
file.setFileName("encrypt_error.html");
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out << result_all;
file.close();
ui.textBrowser->clear();
QUrl myurl1;
myurl1=QUrl::fromLocalFile( "encrypt_error.html" ) ;
ui.textBrowser->setSource(myurl1);
}

I had to use it for another exe program that is cjpeg.exe. I used the following code


void steg::stego()
{
QProcess *P1 =new QProcess ;
char steg_comand[]= "-steg";
char q_comand[]= "-q";
QStringList s2;
s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;
P1->setReadChannelMode(QProcess::MergedChannels);
P1->start( QString("cjpeg.exe"),s2 );
P1->waitForFinished();
QString result_hide= P1->readAllStandardOutput();
QFile file1;
//QDir::setCurrent("E:");
file1.setFileName("hide_error.html");
file1.open(QIODevice::WriteOnly);
QTextStream out(&file1);
out << result_hide;
file1.close();

QUrl myurl2;
myurl2=QUrl::fromLocalFile( "hide_error.html" ) ;
ui.textBrowser->setSource(myurl2);
}
The above code is suppose to convert a .ppm(image file) to jpeg while hiding a text file in it. If all is ok then no output is thrown on the console else one gets an error message.
I deliberately choose parameters to generate the error message but i get blank hide_error.html(which do get created everytime). cjpeg.exe does work since when all parameters are ok I get the jpeg file made. When I run the cjpeg command on command prompt or through a .bat file i get the messages on the console.
In order to verify the code I just replaced cjpeg.exe with burp.exe and i immediately got the error message of burp in my text browser. I know the problem is with cjpeg.exe.But the same thing is fine on command prompt. In fact it is runing even through this code since i got the desired file ( as output ) . I donot know what is the problem.
Could u tell please me How to debug and resolve??
I have been trying forlast three days, but no luck.

jacek
4th November 2006, 15:44
I know the problem is with cjpeg.exe.But the same thing is fine on command prompt. In fact it is runing even through this code since i got the desired file ( as output ) . I donot know what is the problem.
Maybe that cjpeg program detects that it wasn't started from the console and sits quietly?

deekayt
4th November 2006, 20:12
Probably that is the problem.I am sure it is not behaving as a normal .exe
I tried to run it through a bat (stego.bat)file in which i wrote the command cjpeg

The code was as


void steg::stego()
{
QProcess *P1 =new QProcess ;
/*char steg_comand[]= "-steg";
char q_comand[]= "-q";

QStringList s2;

s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;

P1->setReadChannelMode(QProcess::MergedChannels);

P1->start( QString("cjpeg.exe"),s2 ); */

P1->start(QString("stego.bat")); OR P1->startDetached(QString("stego.bat"));
P1->waitForFinished();
QString result_hide= P1->readAllStandardOutput();

QFile file1;
//QDir::setCurrent("E:");
file1.setFileName("hide_error.html");
file1.open(QIODevice::WriteOnly);

QTextStream out(&file1);
out << result_hide;
file1.close();
//ui.textBrowser->clear();
QUrl myurl2;
myurl2=QUrl::fromLocalFile( "hide_error.html" ) ;
ui.textBrowser->setSource(myurl2);
}

When I used P1->start(QString("stego.bat)); the dos screen appeared and I found the error message(as it should have come) and then the screen disappeared since I have not put any code to stop that. It means there was output to console as I want it . But it didnot get captured to QString result_all . How can I capture it (but keeping only start()) and then redirect to textbrowser.

when I used P1->startDetached (QString("stego.bat)); as expected no screen appeared and the cjpeg command did not run. And interestingly i get the out put as

C:\Qt\4.1.3\stegform1\release>cjpeg

where "C:\Qt\4.1.3\stegform1\release" is the current directory and cjpeg is thecommand written in stego.bat. If i could simulate "enter" after cjpeg in stego.bat perhaps it would have executed.
Can u suggest a way out. I cannot change cjpeg.exe.

jacek
4th November 2006, 21:01
If you have access to cjpeg sources, you could check why it behaves like that and maybe you will find a way to fool it.

deekayt
5th November 2006, 18:06
changing cjpeg.exe is out of question
how can i have Qprocess -> start() and still read the std out puts.that perhaps may solve the problem.also with Qprocess-> start() how to keep the console screen on instead of closing on its own.Like we useto stop the screen with getchar();

jacek
5th November 2006, 18:52
changing cjpeg.exe is out of question
I didn't write anything about changing cjpeg.exe.

deekayt
9th November 2006, 16:42
Dear JACEK
my Query is not still answered.Do tell how to circumvent this problem.
That is the last thing left in my project .
I know you can get me out of this.
Thanks

jacek
9th November 2006, 18:16
my Query is not still answered.Do tell how to circumvent this problem.
I've already told you: take a look at cjpeg sources and see why it behaves like that, then you can look for a solution.

deekayt
10th November 2006, 17:34
how can i have Qprocess -> start() and still read the std out puts.that perhaps may solve the problem.also with Qprocess-> start() how to keep the console screen on instead of closing on its own.Like we useto stop the screen with getchar();

jacek
13th November 2006, 19:37
I've found some cjpeg.exe in the Internet (here (http://www.cs.washington.edu/education/dl/tools/screen_capture/)) and tested it with Qt 4.1.5 on windows and I had no problem to capture its output.

So either:
you have some other cjpeg.exe that behaves in a different way,
your cjpeg is compiled in a weird way,
there's something wrong with your program.

deekayt
15th November 2006, 19:24
JACEK
I must thank you for all the pains you would have taken to look for CJPEG.EXE on the net and then testing it.
Infact this CJPEG.EXE is from Independent JPEG group ( VERSION 6) .The same program ( VERSION 4) has been modified for data hiding in JPEG images. ANd some more switches have been provided.
Now instead of just converting a PPM file to JPEG one can add a data file with -steg switch in the JPEG file so formed.( This modification perhaps has not been done in VERSION 6 )

cjpeg -steg <filename> image.ppm image2.jpg

is the way it works.
Now there is a limit to the amount of data one can hide in the JPEG file. When all the filenames are OK and data to be hidden is not exceeding there is no message meaning the thing has worked fine.
But if the data is too much to be loaded or <filename> or image.ppm is missing then the error message come. Now this happens on the comd prompt and not through my program.
I couldhave attached the zipped file but it is 2 mb.I am sending it in email. Please have a look at it.You have brought me till here.Thanks

deekayt
15th November 2006, 19:34
At Which Email Should I Send 2 Mb Zip File.

jacek
15th November 2006, 20:36
At Which Email Should I Send 2 Mb Zip File.
Don't send me your program, instead attach only the cjpeg.exe and I will see if I can make it work.

There rest is your assignment and you should do it yourself. All I can do is to try to give you some advises.

deekayt
17th November 2006, 10:49
I am attaching the cjpeg.exe alongwith
The command line utility is

cjpeg -steg <filename1> filename2.ppm filename3.jpg

where in the filename2.ppm changes to filename3.jpg ( that is it is compressed) and while doing so filename1( could be any type of file) gets embedded in the filename3.jpg.

Error messages are given when files donot exist or the filename1 is too large to be hidden ( it should be lesser than 10 % of the filename2.ppm size )
If everything is alright then the data is hidden and no message is generated at all.

jacek
17th November 2006, 19:31
Your cjpeg.exe also works well with my test program (see attachment).

deekayt
19th November 2006, 10:44
Dear JACEK,
1.Thanks a lot for verifying the CJPEG.EXE.

2.I am enclosing the extracts of the files main.cpp, steg.h, steg.cpp where cjpeg.exe is used. I have more or less incorporated the things which you have given but it does not work. Do I have to necessarily include “main.moc” .
3. I believe I need to connect the readyReadStandardOutput() as you have done

connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read() ) );
rest most of the things are same.
Is the second connect also required

connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
Could tell me how to adjust in the existing code.
I am not able to figure out.
Please have a look at my abridged code put in the zip file.
Thanks

jacek
19th November 2006, 14:46
Do I have to necessarily include “main.moc” .
No, you need this only if you use Q_OBJECT macro inside a .cpp file.


I believe I need to connect the readyReadStandardOutput() as you have done
This is the usual approach, but reading the output after waitForFinished() also works (at least under Linux).


Is the second connect also required
connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
No, unless you want to close your application when the process exits.

deekayt
23rd November 2006, 16:55
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>
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"

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>
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
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"))
{
QStringList s2;
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
steg t (s2);
}

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.

jacek
23rd November 2006, 17:26
but it is public QDialog whereas you have gone for public QObject.Do I have to stick to Public Qobject only.
What is the difference between QObject and QDialog?


steg t (s2);
You create "t" on the stack and it gets destroyed immediately (together with QProcess), because it goes out of scope.
Instead of creating a new dialog, move the code that creates the process to steg::stego() slot.

deekayt
25th November 2006, 19:46
It does not work. I have now made steg.h as

#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

and steg.cpp as


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() ;
//QProcess *_proc;
_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);
read();
}
I have to have _proc declared in steg.h since I use it in read() also.
I donot know where is the problem

jacek
25th November 2006, 20:25
What happens if you add:
connect( _proc, SIGNAL( started() ), QApplication::instance(), SLOT( aboutQt() ) );?

P.S. There is no sense in calling read() in stego(), QProcess will send a signal when there is something to read.

deekayt
26th November 2006, 19:03
The code now looks like

QStringList s2;
s2 << "-steg" << "coded.txt" << "-q" << ui.compressionspinBox->text() << "cleanimage.ppm" << ui.jpeglineEdit ->text() ;
//QProcess *_proc;
_proc = new QProcess( this );
_proc->setReadChannelMode( QProcess::MergedChannels );

connect( _proc, SIGNAL( readyReadStandardOutput() ), this, SLOT( read()));
connect( _proc, SIGNAL( started() ), QApplication::instance(), SLOT( aboutQt() ) );

// connect( _proc, SIGNAL( finished(int, QProcess::ExitStatus) ), QCoreApplication::instance(), SLOT( quit() ) );
_proc->start(("cjpeg"),s2);

//read();


Now I get the About QT inboth the case that is when there would be error message and when there is no error message.
I know that the program has worked fine ( data has been succesfully hidden ) after seeing the concerned file and classicaly speaking noerroror otherwise any message is not given on thecommand console hence nothing should come in the message pop also.But The About QT screen does come everytime.
The screen snapshot is attached as zip.
What do you say??

jacek
26th November 2006, 19:42
Now I get the About QT inboth the case that is when there would be error message and when there is no error message.
This means that the program was started successfully. Maybe you kill it immediately? Does my test program work on your system?

deekayt
30th November 2006, 08:55
Dear JACEK

I have tried to run the main.cpp but could not.
How did you run it .
I understand that I should have some form ( Q Dialog) and then on click of button the object should be made
thus runing the cjpeg.exe,since you had incorporated in the constructor only.
The error which I got while doing MAKE is in the erro_text_file.txt attached alongwith.
The code is at the test.zip file.

jacek
30th November 2006, 09:55
I have tried to run the main.cpp but could not.
How did you run it .
My program, without any modifications, should compile without any problems. In fact it's a self contained example which verifies that cjpeg.exe output can be captured --- it doesn't need any modifications to run.


The error which I got while doing MAKE is in the erro_text_file.txt attached
If you look closely you will see, that all error messages are referring to your code. If run qmake again, it should compile.

deekayt
30th November 2006, 14:40
I tried your code without modification
I should be getting the error since you had supplied invalid arguments "aaa" and "bbb"

_
proc->start( "cjpeg", QStringList() << "aaa" << "bbb" );

and one should be getting the message box with the error captured.
The test1 does get compiled but when i run it nothing happens.It does get started which I see in the process runing in the Task Manager window of the operating system.
but that's all.No message at all.
I am attaching the whole folder which I compiled.
You will notice that I have edited makefile since I donot want any references to debug . Because when I make with the unedited makefile I get the error as captured in error_text1_file.txt.I did not want to repair the QT make thing hence this shortcut of first deleting all refernces to debug in makefile and then making the makefile.
Is it because of this shortcut that I am not getting the right thing from your main.cpp or is it something else.

Secondly you mentioned about the

"If you look closely you will see, that all error messages are referring to your code."

how to get this vtable error corrected

jacek
30th November 2006, 20:44
The test1 does get compiled but when i run it nothing happens.
How do you start it?


You will notice that I have edited makefile since I donot want any references to debug .
There is no need to edit automatically generated files. You have three possibilities:

compile Qt libraries in debug mode,
use "make -f Makefile.Release",
add:
CONFIG -= debug_and_release
CONFIG += releaseto the .pro file.


Secondly you mentioned about the
And I've also mentioned the solution.

deekayt
4th December 2006, 01:34
How am I suppose to start the test1.exe.
It is there in the release folder
I just double click hoping that message box with error will come but nothing happens.
I tried runing test1.exe from comd prompt but nothing happens.
I am still stuck.

jacek
4th December 2006, 01:55
I just double click hoping that message box with error will come but nothing happens.
If you start the program by double-clicking on it, the current directiry will be set to your desktop (AFAIR), but the program expects that cjpeg.exe will be in the current directory.


I tried runing test1.exe from comd prompt but nothing happens.
How? Is cjpeg.exe in the current directory?

deekayt
4th December 2006, 10:25
Once the test1.exe is made in the release directory of test1 folder I copy cjpeg.exe there with all other files which are required to be used . I have been doing the same for all other programs.After that either one double clicks the test1.exe after navigating to release folder or one can copy a shortcut to the desktop ( both work).I am sure that is not the problem.

jacek
4th December 2006, 14:49
What happens if you change:

proc->start( "cjpeg", QStringList() << "aaa" << "bbb" );
to:

proc->start( QCoreApplication::applicationDirPath() + "/cjpeg.exe", QStringList() << "aaa" << "bbb" );?

deekayt
5th December 2006, 01:34
It is till the same
When I see in the task manager test1.exe is runing but visually there is nothing.main.cpp looks as below


#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" );
_proc->start( QCoreApplication::applicationDirPath() + "/cjpeg.exe", 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"

I was just wondering why you have given
QM
QMessageBox::information( 0, "test", _proc->readAllStandardOutput() );

should it not be "Test".Though I changed to that too but still no result.
I want to know that when you started your exe what message did you get. Can you tellme that.

jacek
6th December 2006, 23:56
I want to know that when you started your exe what message did you get. Can you tellme that.
Exactly the same one that cjpeg.exe outputs to the console when you start it with wrong parameters.

deekayt
7th December 2006, 12:29
Well
Earlier I was compiling after deleting all the refrences to debug from Makefile.And it was compiling . But as you told I now tried
qmake -project
qmake
make -f Makefile.Release

In the folder test1 I only kept main.cpp as you gave
and I came up with hordes of compilation error.
I am not too sure to sort them out as they refer to libraries
I am enclosing those errors in the error_text_file.txt file attached alongwith.
Can you tellme the way out.
Till now my approach of "compiling after deleting all the refrences to debug from Makefile" was cool.

jacek
7th December 2006, 19:27
make -f Makefile.Release
Are you sure you did that?

deekayt
7th December 2006, 21:57
Sorry
But even after using make -f Makefile.Release
I get the same error
The error file is attached

jacek
7th December 2006, 22:33
It looks like there's something wrong with your MinGW installation. Can you compile any other Qt applications?

deekayt
8th December 2006, 00:23
I also think so
I can compile all others except the one which you gave
In fact I am compiling with cjpeg.exe also but that problem of not being able to catch error messages persists.
I will install again and come back to you.
Thanks

deekayt
8th December 2006, 06:45
Dear JACEK
I have installed QT again.Now I am ableto compile your main.cpp .
But the test1.exe doesnot give me any error message
Can you send me whatever you compiled and ran on your computer.
The error message expected is attached at cjpeg_error.txt file which I got on command line .

jacek
8th December 2006, 11:33
But the test1.exe doesnot give me any error message
Connect something to QProcess::started() signal to check if cjpeg.exe starts.

deekayt
9th December 2006, 13:47
Dear JACEK
Please refer to post 31. The program does start succesfully.
Can you send me the exe which incorporated cjpeg.exe.

jacek
9th December 2006, 15:34
I think I know why it works on my system --- I have "CONFIG += console" in my .pro file. The problem is that this cjpeg.exe appears to be a 16-bit executable. Are you sure you can't recompile it?

deekayt
10th December 2006, 01:31
I added "CONFIG+=console". Now when I run the console black window appears and after sometime The eror message appears as

16 Bit MSODS Subsystem
c:\WINDOWS\system32\ntvdm.exe
Error while setting up environment for the application.Choose 'close'to terminate the application

You are correct the problem is 16 bit v/s 32 bit only
Recompiling cjpeg.exe is out of question .
What do I do?
Why this 16 bit exe otherwise executes through my program since I do get the end results but I am not able to catch the error messages.
Any way please tell me a way out now since the problem seems to be pinpointed .

wysota
10th December 2006, 09:10
Why is recompiling out of question?

The problem is that this application seems to be very old and doesn't behave correctly when used with QProcess. The problem is with the cjpeg and not with your Qt application.

jacek
10th December 2006, 14:32
The eror message appears as
16 Bit MSODS Subsystem
c:\WINDOWS\system32\ntvdm.exe
Error while setting up environment for the application.Choose 'close'to terminate the application
You can run your application in windows 95 compatibility mode. You can set that when you right-click on the executable and choose Properties (or something similar) from the menu.


Recompiling cjpeg.exe is out of question .
Why? You are not going to change it.