PDA

View Full Version : QProcess' writeToStdin



Shlainn
19th September 2006, 09:14
Hi all,

I have and external mySQL C API program which needs to receive the data to search for in the database.

The following code displays the connection to the Qprocess and it works fine

void DatabaseLogin::connectAccept()
{

proc = new QProcess( this );
QLabel *label = new QLabel("tester",0);
label->show();

QDir *directoryPath = new QDir("f:/projek/Functional_units/Database_sources/files");

proc->setWorkingDirectory(*directoryPath);
// Set up the command and arguments.
proc->addArgument( "cmd" );
proc->addArgument( "/c" );
proc->addArgument( "fdatabase" );
proc->addArgument( "epr" );

proc->start();

connect( proc, SIGNAL(readyReadStdout()),
this, SLOT(readFromStdout()) );

if ( !proc->start() )
{
// error handling
QMessageBox::critical( 0,
tr("Fatal error"),
tr("Could not start the program."),
tr("Quit") );
exit( -1 );
}
}

void DatabaseLogin::readFromStdout()
{
// Read and process the data.
// Bear in mind that the data might be output in chunks.
output->append( proc->readStdout() );
}

please note that ouput is just the verify the results obtained, so the program is called fdatabase and one of the variables are the database called epr. I can't send the field to look for using the above method because the API run differently to another program.

In the API I have scanf and thus from the QT3 I want to write to stdIn any advise/questions? When I add
proc->writeToStdin("1123"); just after the start nothing wants to work :(

Please help!
Thanks :)

wysota
19th September 2006, 11:39
When I add
proc->writeToStdin("1123"); just after the start nothing wants to work :(
Add a newline ("\n") to the string you send.

Shlainn
19th September 2006, 14:08
Ok added the "\n":

proc->addArgument( username );
proc->addArgument( database );
output->append( (proc->arguments()).join(" "));
proc->start();

proc->writeToStdin("Saurabh\n");
connect( proc, SIGNAL(readyReadStdout()),
this, SLOT(readFromStdout()) );

if ( !proc->start() )
{

But still nothing. Here is the .c code:

int SetQuery()
{ char query[1024];
char serialnmr[20];
//char *serialnmr;
//serialnmr = "Saurabh";
printf("input");
scanf("%s",serialnmr);

printf("%s\n",serialnmr);
sprintf(query, "SELECT * FROM users WHERE name='%s'",serialnmr);


The .c works in the command line but using QT3 it doesn't want to work.