Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QProcess::setWorkingDirectory has no effect on Windows

    General and Desktop
    2
    6
    8331
    Loading More Posts
    • 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
      Violet Giraffe last edited by

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • V
          Violet Giraffe last edited by

          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 Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

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

            1 Reply Last reply Reply Quote 0
            • V
              Violet Giraffe last edited by

              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 Reply Quote 0
              • V
                Violet Giraffe last edited by

                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 Reply Quote 0
                • First post
                  Last post