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. QProcess::setWorkingDirectory has no effect on Windows
Forum Updated to NodeBB v4.3 + New Features

QProcess::setWorkingDirectory has no effect on Windows

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 10.2k 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    Here's what I'm trying to do:

    @QProcess * process = new QProcess;
    process->setWorkingDirectory("C:/temp_dir/");
    process->setStandardOutputFile(1.txt);

    process->start("qmake", QStringList() << "-tp" << "vc" << "-r");
    process->waitForFinished();@

    The directory "C:/temp_dir/" exists. I can clearly see that setWorkingDirectory has no effect, because this dir contains a valid qmake project, and Visual Studio project is not generated when I run the command. Also, 1.txt file is created in the .exe working dir and not in temp_dir, but I'm not sure if that's also a bug or expected behavior.

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You use relative path in call to setStandardOutputFile. This path is relative to the working dir of your app, not the process you're about to start. So either enter path relative to your exe(not the working dir as it may vary!) or use a full path. That's the expected behavior.

      As for the setWorkingDirectory I think you came to wrong conclusions because it does work. You can easily check that by running a program that prints working directory.

      Does it work if you run it from command line? Are all environment variables etc. available to the process you start?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        I've switched from QProcess::start to startDetached, and now I'm positive it doesn't work. The following command

        @QProcess::startDetached("cmd.exe", QStringList() << "/C cmd", "C:/test_folder/");@

        launches cmd.exe in the application's working dir, not in C:/test_folder. test_folder exists and is accessible.

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          It works for me. What Qt and Windows version are you using?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Violet Giraffe
            wrote on last edited by
            #5

            Qt 5.2.1, Windows 7 x64.
            Update: it turned out to be a very silly mistake on my part. I had 2 similar lines of code nearby, and of course the one I was editing wasn't the one that was being executed. It works now.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Violet Giraffe
              wrote on last edited by
              #6

              And yet I'm having problems. Working dir is now fine, but something in the way I use QProcess is wrong.

              I'm trying to start a console and execute arbitrary commands there. Like so:

              @QString command = "qmake -v > 1";
              QProcess::startDetached("cmd.exe", QStringList() << (QString("/C ") + command), workingDir);@

              And it works fine, file 1 is created and contains qmake -v output. However, this command:

              @QString command = "qmake -tp vc -r > 1";@
              Doesn't work. I launch it with workingDir set to a dir with a valid Qt project. File 1 is created, but it's blank. Qmake launches, but then closes down immediately, the output file is blank, no project is generated.

              "dir > 1" is executed as expected, however, printing the contents of workingDir and redirecting it into a file created also in workingDir. Any tip on how to debug this? I'd think it's a qmake issue, but if I run cmd from my workingDir and execute "qmake -tp vc -r" or "qmake -tp vc -r > 1" - it works!

              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