0

Trying to run this code in the main function of a console app in QT but it only starts up the Blender GUI. These arguments should be starting a background render.

I tested the arguments to be correct and they work fine on CMD. This seems to be a blender specific issue but I might be wrong. It seems as though, using QProcess it doesn't allow for Blender to use the arguments. It launches the app without passing any arguments.

QProcess myProcess;
QString blender = "C:/Program Files/Blender Foundation/Blender/blender.exe";
QStringList arguments;
  arguments << "blender" << "-b" << "E:/my/file.blend" << "-o" << " E:/my/output/folder/"<< "-a";

myProcess.start(blender,arguments);

Edit:

So browsing through SO, I found something that's working but this isn't using the QT functionality. I'd rather find the QT way of doing this. What it's essentially doing is running CMD and launching blender through the CMD. Is there a way I can do this using QT?

QDir::setCurrent(blender);
system("blender -b E:\\Blender\\BlendSwap\\55510_Ciclos_Town_-_10_Male_Characters\\cidade_ciclos-bonecos.blend -o E:\\Blender\\BlendSwap\\55510_Ciclos_Town_-_10_Male_Characters\\exp\\frame_### -a");
  • 1
    Silly question but... what is the first item "blender" in `arguments` for? – G.M. Apr 15 '17 at 08:44
  • Do not forget, that if `myProcess` instance of `QProcess` will be destroyed, launched process will be automatically terminated. To avoid this you can use `startDetached` instead of `start` or run `QProcess::waitForFinished()` after you have started the process. – Max Go Apr 15 '17 at 15:44
  • No, that's actually a good point. In CMD you would CD to the blender folder and "blender" is the flag to launch blender. I don't know what's wrong but QProcess is working so erradically. Sometimes it launches blender gui sometimes it doesn't launch anything at all. A couple times it launched the actual project in the GUI. Note: I have been experimenting with "\" and "/" for the project paths. It seems like it likes one over the other but I can't recreate the problem. – LetTheWritersWrite Apr 15 '17 at 16:01
  • @G Ok, I recreated the problem. This is very strange. It's not liking the "-b" flag which is to make it run in the background. The space you see in my code on the -b was actually making the program skip that flag. Long story short, I can actually just pass my project file as an argument and it'll run fine. Is my only solution is to run CMD and run blender through it? – LetTheWritersWrite Apr 15 '17 at 16:32
  • @MaxGo Thanks for the input Max. Now that I figured out that it's my arguments it wasn't liking, I'm finding that startDetached() is launching blender just the same as start(). I tried reading the documentation for both your suggestions but I can't understand what it's actually meant to do? waitForFinished seems to suggest that it should be started as a seperate thread or it will lock up the program and startdetached i could not understand its purpose. – LetTheWritersWrite Apr 15 '17 at 16:37
  • I added a working solution but it's not using QT. – LetTheWritersWrite Apr 15 '17 at 17:22

1 Answers1

1

Thanks for @MaxGo and @G.M. because they set me on the right path.

Two things: First off, tt's true that using the "blender" flag was one of the issues. I can't launch the .exe file and also expect blender to take in the arguments.

Second, start() will not work, you do need to use startDetached or execute() for it to work.

Below is the final code to make this launch correctly.

QDir::setCurrent(blenderDirectory);
myProcess.startDetached("blender -b " + projectPath + " -o " + projectOutput + " -a");