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. executing the OS command using QProcess
Forum Updated to NodeBB v4.3 + New Features

executing the OS command using QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 296 Views
  • 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.
  • G Offline
    G Offline
    gaargot
    wrote on last edited by gaargot
    #1

    hi
    Debian OS
    Qt Creator 10.0.2 Based on Qt 6.4.2 (GCC 13.2.0, x86_64)

    ask for help, how to fix it
    This code works perfectly. Converts a file to pdf:

    QProcess *process = new QProcess(parent);
    QStringList list;
    process->waitForStarted();
    process->waitForReadyRead();
    process->start("unoconv", list <<"-f"<<"pdf"<<"-o"<<"/somepath/file.pdf"<<"/somepath/somefile.odt");
    process->waitForFinished();
    

    This code does not work. The file is not being copied:

    QProcess *process = new QProcess(parent);
    QStringList list;
    process->waitForStarted();
    process->waitForReadyRead();
    process->start("/usr/bin/dd", list <<"if='/somepath/somepath/file.pdf'" << "of='/somepath/file.pdf'");
    process->waitForFinished();
    

    At first I tried to copy using 'cp'. It doesn't work either
    Moreover, both commands work perfectly in the OS console

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gaargot
      wrote on last edited by
      #2

      Solved the problem, the following code works:

      process->start("/usr/bin/dd", list <<"if=/somepath/simefile.pdf"<<"of=/somepath/file.pdf");

      thanks

      1 Reply Last reply
      0
      • G gaargot has marked this topic as solved on
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        What's wrong with QFile::copy() when you only want to copy a file to another location?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • G Offline
          G Offline
          gaargot
          wrote on last edited by
          #4

          Thanks for the tip. I will definitely try it too

          JonBJ 1 Reply Last reply
          0
          • G gaargot

            Thanks for the tip. I will definitely try it too

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @gaargot
            Apart from @Christian-Ehrlicher's suggestion that if you want to copy a file do it via QFile::copy() rather than an OS command. Although your code "works" you should at least be aware that it is "wrong". You are calling waitForStarted() and waitForReadyRead() before you have start()ed the process. That makes no sense, they probably just return immediately since there is nothing running to wait for! If you needed them here --- which you do not --- they should come after start() and before waitForFinished(), for future reference.

            1 Reply Last reply
            2

            • Login

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