Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. postgresql backup and restore
Qt 6.11 is out! See what's new in the release blog

postgresql backup and restore

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PabloArgP Offline
    PabloArgP Offline
    PabloArg
    wrote on last edited by
    #1

    I have some problem trying to restore a backup made with pg_dump (it´s a postgres command).
    When I restore the backup using the postgresql command from console works fine:
    psql "dbname=myDB host=localhost user=myUsr password=Mypwd" < myBackup

    So I tried to implement the same function in QT via QProcess without success.
    MyProcess.setNativeArguments(""dbname=myDB host=localhost user=myUsr password=Mypwd" < myBackup")
    MyProcess.setProgram("psql");

    Somebody has some example how to do it correctly.

    Many thanks
    Pablo

    1 Reply Last reply
    0
    • PabloArgP Offline
      PabloArgP Offline
      PabloArg
      wrote on last edited by
      #2

      Hi all,

      Well I found the solution searching in Internet and I found this link:
      https://www.codeproject.com/Articles/360472/Postgres-Database-Backup-Restore-From-Csharp

      Looks that psql for some reason cannot be launch inside of Qt, so I created a bat file that contains the psql command and their parameters. Then I call that bat file from QProcess and Finally works fine!!!

      Anyway I will keep open this ticket for a while if somebody has a better solution.

      Pablo

      jsulmJ 1 Reply Last reply
      0
      • PabloArgP PabloArg

        Hi all,

        Well I found the solution searching in Internet and I found this link:
        https://www.codeproject.com/Articles/360472/Postgres-Database-Backup-Restore-From-Csharp

        Looks that psql for some reason cannot be launch inside of Qt, so I created a bat file that contains the psql command and their parameters. Then I call that bat file from QProcess and Finally works fine!!!

        Anyway I will keep open this ticket for a while if somebody has a better solution.

        Pablo

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #3

        @PabloArg Processes started using QProcess do NOT run inside your Qt app!
        The problem is that you pass the parameter wrongly: you should not pass all parameters as one string.
        You should read QProcess documentation, there are examples:

        QObject *parent;
        ...
        QString program = "./path/to/Qt/examples/widgets/analogclock";
        QStringList arguments;
        arguments << "-style" << "fusion";
        
        QProcess *myProcess = new QProcess(parent);
        myProcess->start(program, arguments);
        

        So, each parameter is put as string in a string list.

        You should connect http://doc.qt.io/qt-5/qprocess.html#errorOccurred to a slot and print the error.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • PabloArgP Offline
          PabloArgP Offline
          PabloArg
          wrote on last edited by
          #4

          Hi jsulm,

          I tried as you said as well, but doesn´t work. Anyway according to QProcess is possible to use Native parameters where your parameters you can put as string and QT will recognize each parameters by spaces between them. I am usign for long time without problem.

          I will close this ticket because looks that this is a problem with psql. And the only solution is create a bat file, and run the bat in QProcess.

          Many thanks to everybody as I said before if you guys found better idea to do this let me know

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved