Results 1 to 6 of 6

Thread: QProcess - Session and Permission

  1. #1
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default QProcess - Session and Permission

    Hi there. Yhis is my first post and I hope someone can help me.

    I'm having a problem with QProcess. I'm trying to execute pg_dump (PostgreSQL backup generator) from my application.

    I added the agument list containing information about user, host, etc. and setted the enviroment variables to store the password.

    I captured the output and received a message from pg_dump that says:

    Qt Code:
    1. pg_dump: [archiver (db)] connection to database "sgtnewnew" failed: could not translate host name "localhost" to address: Unknown host
    2. pg_dump: *** aborted because of error
    To copy to clipboard, switch view to plain text mode 

    The command line I used was:

    Qt Code:
    1. C:\Arquivos de programas\PostgreSQL\8.2\bin>pg_dump.exe -i -h localhost -p 5432 -U postgres -F c -b -v -f C:\testeBat1.backup sgtnewnew
    To copy to clipboard, switch view to plain text mode 

    I made many tests and it seams that pg_dump.exe has not found it dependencies or something else. I tried to create a .bat file and place it in the postgres/bin folder and then call it using QProcess. I got the same error message. When I ran this .bat file by clicking twice over it, the backup was sucessfully done.

    I tried to run it using system(c++ function) and it worked fine. The problem is that I need to capture the output (stdout) and QProcess does it for me.

    Dows anyone had any problem like this??

    Thans for now

    Mário

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Session and Permission

    How do you start the process?
    On win the arguments have to be contained within quotes. See the documentation for QProcess::start()

  3. #3
    Join Date
    Dec 2007
    Posts
    2
    Qt products
    Qt3
    Platforms
    Windows

    Angry Re: QProcess - Session and Permission

    This is my entire code. I seams pg_dump received all my parameters, but something was missed and it returned error. Note that I am using the full path of to pg_dump. Yhis _database objectc gives the all information about the database I want to backup :


    Qt Code:
    1. string host = _database->host().empty() ? "localhost" : _database->host();
    2. int port = _database->portNumber() == 0 ? 5432 : _database->portNumber();
    3. string path = "C:\\Arquivos de programas\\PostgreSQL\\8.2\\bin";
    4. string backupExe = "\"" + path + "\\pg_dump.exe\"";
    5. string fileName = string(fileLineEdit->text().latin1());
    6. string envPassword = "PGPASSWORD=" + _database->password();
    7.  
    8. if(!_process)
    9. {
    10. _process = new QProcess(0);
    11. connect(_process, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()));
    12. connect(_process, SIGNAL(readyReadStderr()), this, SLOT(readFromStderr()));
    13. }
    14. QDir dir(path.c_str());
    15. _process->setWorkingDirectory(dir);
    16.  
    17. _process->clearArguments();
    18. _process->addArgument(backupExe.c_str());
    19. _process->addArgument("-i");
    20. _process->addArgument("-h");
    21. _process->addArgument(host.c_str());
    22. _process->addArgument("-p");
    23. _process->addArgument(Te2String(port).c_str());
    24. _process->addArgument("-U");
    25. _process->addArgument(_database->user().c_str());
    26. _process->addArgument("-Fc");
    27. _process->addArgument("-b");
    28. _process->addArgument("-v");
    29. _process->addArgument("-f");
    30. _process->addArgument(fileName.c_str());
    31. _process->addArgument(_database->databaseName().c_str());
    32.  
    33. QStringList* strList = new QStringList();
    34. strList->append(envPassword.c_str());
    35.  
    36. if(!_process->start(strList))
    37. {
    38. QMessageBox::information(this, "Information", "Error starting process");
    39. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

    --------------------------------------------------------------------------------

    Obs: I am using QT 3.2.0

  4. #4
    Join Date
    Mar 2008
    Location
    Brazil
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Session and Permission

    Hello,

    Using Qt 4.3... In Windows :P~...

    • Copy pg_dump.exe to your release folder
    • Copy all dependencies (zlib1.dll, libintl3.dll... ) to the same folder


    This code work's great for me:

    Qt Code:
    1. void ... :: on_backup_do_BD_triggered()
    2. {
    3. QString nome_arquivo = QFileDialog::getSaveFileName( this,
    4. "Realizar Backup do Banco em...",
    5. ".",
    6. "Arquivo SQL (*.sql)" );
    7.  
    8. QProcess pg_dump;
    9.  
    10. QString nome;
    11. QStringList parametros;
    12.  
    13. // Definindo a variavel de ambiente que tera o password
    14. QStringList var_de_ambiente;
    15.  
    16. var_de_ambiente << "PGPASSWORD=" + banco->password();
    17.  
    18. pg_dump.setEnvironment( var_de_ambiente );
    19.  
    20. #ifdef Q_OS_WIN32
    21. nome = "pg_dump.exe";
    22.  
    23. int porta = banco->port();
    24.  
    25. parametros << "-f" << nome_arquivo
    26. << "-F" << "p"
    27. << "-U" << banco->userName()
    28. << "-p" << QString::number( porta == -1 ? 5432 : porta )
    29. << "-h" << banco->hostName()
    30. << banco->databaseName();
    31. #endif
    32.  
    33. pg_dump.start( nome, parametros );
    34. pg_dump.waitForStarted();
    35. pg_dump.waitForFinished();
    36.  
    37. if ( pg_dump.exitCode() )
    38. {
    39. QMessageBox erro( this );
    40.  
    41. erro.setWindowTitle( "Erro de backup" );
    42. erro.setIconPixmap( QPixmap( ":/48x48/alert.png" ) );
    43. erro.setText( "Ocorreu um erro ao tentar fazero backup do BD." );
    44.  
    45. erro.exec();
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 

    NOTE: PGPASSWORD sets the password used if the server demands password authentication. Use of this environment variable is not recommended for security reasons (some operating systems allow non-root users to see process environment variables via ps);
    Last edited by diogolr; 8th July 2008 at 08:33.

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Session and Permission

    Dear All

    I use the same way to backup, but the problem I have right not is to gzip the file,

    I am using Windows and 4.5.0 I would like to gzip the backup I took.

  6. #6
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - Session and Permission

    any body can help me for this?

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.