Hi, I am attempting to create a scenario where my program uses plink to create a ssh tunnel, and once it knows the tunnel is up, then log in to a mysql database. The pertinent piece of code that does this is as follows:
Qt Code:
  1. bool programMain::serverConnect() {
  2. //make the tunnel channel display:
  3. tunnel.setProcessChannelMode(QProcess::SeparateChannels);
  4. tunnel.setReadChannel(QProcess::StandardOutput);
  5. //spawn the SSH tunnel:
  6. tunnel.start("c:/progra~1/PuTTY/plink.exe -l user -ssh -pw password -C -v -N -L 9999:111.111.111.111:9999 remotecomputer.domain.com");
  7. //open SSH tunnel
  8. if (!tunnel.waitForStarted(20000)) {
  9. QMessageBox::critical(0, qApp->tr("Could not open SSH Tunnel"),
  10. qApp->tr("Unable to create secure ssh tunnel!\n\n")+ qApp->tr("\n\nClick Cancel to exit."), QMessageBox::Cancel,
  11. QMessageBox::NoButton);
  12. return false;
  13. }
  14. //hold the database login until the tunnel has responded with a login message:
  15. if (!tunnel.waitForReadyRead(20000)) {
  16. QMessageBox::critical(0, qApp->tr("SSH connection not responding!"),
  17. qApp->tr("SSH response timed out!\n\n")+ qApp->tr("\n\nClick Cancel to exit."), QMessageBox::Cancel,
  18. QMessageBox::NoButton);
  19. return false;
  20. }
  21.  
  22. //connect to the server:
  23. if (!createConnection(login.serveraddy, login.databasename, login.username, login.password, login.port)) {
  24. return false;
  25. }
  26. return true;
  27. }
To copy to clipboard, switch view to plain text mode 

The results are as follows:

-If I run the code as-is, it will give me the "SSH connection not responding!" message, because for some reason ReadyRead never is triggered.

-If i remove the "if (!tunnel.waitForReadyRead(20000)) {" piece, then it creates the ssh tunnel fine, however it does not wait to try to connect to the database after plink is started *and* plink is done connecting, so the database connection fails.

This was what I was hoping to accomplish with the "if (!tunnel.waitForReadyRead(20000)) {" code, to make it wait till plink spit out the login successful text, and then continue on to log in to MySql.

if I change "tunnel.setProcessChannelMode(QProcess::SeparateCh annels);" to "tunnel.setProcessChannelMode(QProcess::ForwardedC hannels);", i can see the terminal showing the login process going through fine, so I can only assume that there is some problem with the wait code.

I could put some kind of timer to wait until most likely the tunnel should be created, but I would like the program to start logging in to mysql as soon as it can after ssh is done, for the best user experience.

any tips on how I could do this?