Results 1 to 3 of 3

Thread: QProcess' writeToStdin

  1. #1
    Join Date
    Sep 2006
    Posts
    4
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default QProcess' writeToStdin

    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
    Qt Code:
    1. void DatabaseLogin::connectAccept()
    2. {
    3.  
    4. proc = new QProcess( this );
    5. QLabel *label = new QLabel("tester",0);
    6. label->show();
    7.  
    8. QDir *directoryPath = new QDir("f:/projek/Functional_units/Database_sources/files");
    9.  
    10. proc->setWorkingDirectory(*directoryPath);
    11. // Set up the command and arguments.
    12. proc->addArgument( "cmd" );
    13. proc->addArgument( "/c" );
    14. proc->addArgument( "fdatabase" );
    15. proc->addArgument( "epr" );
    16.  
    17. proc->start();
    18.  
    19. connect( proc, SIGNAL(readyReadStdout()),
    20. this, SLOT(readFromStdout()) );
    21.  
    22. if ( !proc->start() )
    23. {
    24. // error handling
    25. QMessageBox::critical( 0,
    26. tr("Fatal error"),
    27. tr("Could not start the program."),
    28. tr("Quit") );
    29. exit( -1 );
    30. }
    31. }
    32.  
    33. void DatabaseLogin::readFromStdout()
    34. {
    35. // Read and process the data.
    36. // Bear in mind that the data might be output in chunks.
    37. output->append( proc->readStdout() );
    38. }
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. proc->writeToStdin("1123");
    To copy to clipboard, switch view to plain text mode 
    just after the start nothing wants to work

    Please help!
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess' writeToStdin

    Quote Originally Posted by Shlainn View Post
    When I add
    Qt Code:
    1. proc->writeToStdin("1123");
    To copy to clipboard, switch view to plain text mode 
    just after the start nothing wants to work
    Add a newline ("\n") to the string you send.

  3. #3
    Join Date
    Sep 2006
    Posts
    4
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: QProcess' writeToStdin

    Ok added the "\n":
    Qt Code:
    1. proc->addArgument( username );
    2. proc->addArgument( database );
    3. output->append( (proc->arguments()).join(" "));
    4. proc->start();
    5.  
    6. proc->writeToStdin("Saurabh\n");
    7. connect( proc, SIGNAL(readyReadStdout()),
    8. this, SLOT(readFromStdout()) );
    9.  
    10. if ( !proc->start() )
    11. {
    To copy to clipboard, switch view to plain text mode 

    But still nothing. Here is the .c code:
    Qt Code:
    1. int SetQuery()
    2. { char query[1024];
    3. char serialnmr[20];
    4. //char *serialnmr;
    5. //serialnmr = "Saurabh";
    6. printf("input");
    7. scanf("%s",serialnmr);
    8.  
    9. printf("%s\n",serialnmr);
    10. sprintf(query, "SELECT * FROM users WHERE name='%s'",serialnmr);
    To copy to clipboard, switch view to plain text mode 

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

Similar Threads

  1. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  2. QProcess start automaticaly needed application
    By raphaelf in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 14:11
  3. Replies: 4
    Last Post: 13th February 2006, 11:35
  4. speed up qprocess readstdout
    By kooshball in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2006, 09:42
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.