PDA

View Full Version : How to code an App that will build QT projects



locke
24th August 2010, 10:13
Hi guys,

Im coding an app that will need to build other Qt projects. The user will select the project to build and my app have to build it and provide the executable.

I think that I can do it by using QProcess but I cannot get it.

Lets get some code


QProcess *firstProcess = new QProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("QDIR", "C:\\Qt\\2010.01\\qt"); // Add an environment variable
env.insert("PATH", env.value("Path") + ";C:\\Qt\\2010.01\\qt\\bin");
env.insert("QMAKESPEC", "win32-g++"); // Add an environment variable
firstProcess->setProcessEnvironment(env);

QString qmake ="qmake.exe";
QStringList arguments;
arguments << m_pathToProjectFiles + "/MyProject.pro" << "CONFIG+=release";

firstProcess->start(qmake, arguments);
firstProcess->waitForFinished();



But it doesn create the Make file. I noticed that QT provides a Qt Command promp, that sets some environment variables. I tried to reproduce that by using the "env.insert" sententences in the code. But it doesnt work.

Another cool thing could be just execute the Qt command promp from the code (so the process programm could be C:\Windows\System32\cmd.exe /K C:\Qt\2010.01\bin\qtenv.bat )

But then, If I execute in the process the cmd, how can I inside that process execute some other programs (like qmake or make). Do I have to create a bat file and execute it from QProcess?

Thanks!!

tbscope
24th August 2010, 10:23
I guess you mean QTDIR and not QDIR.

But you don't need that anyway. Just call the correct qmake and it will find everything Qt related.

Also, check if the command you want to execut is actually correct. Use the error signal.

An example to build a program:

/home/myuser/qtdir/someversion/bin/qmake /home/myuser/myproject/myproject.pro
This will generate the Makefile in the current folder.

locke
24th August 2010, 10:39
Doesnt work, I have changed that


QProcess *firstProcess = new QProcess;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
//Next line was changed
env.insert("QTDIR", m_pathToProjectFiles); // Add an environment variable
env.insert("PATH", env.value("Path") + ";C:\\Qt\\2010.01\\qt\\bin");
env.insert("QMAKESPEC", "win32-g++"); // Add an environment variable
firstProcess->setProcessEnvironment(env);
//Next line was changed
QString qmake ="C:/Qt/2010.01/qt/qmake/qmke.exe";
QStringList arguments;
arguments << m_pathToProjectFiles + "/MyProject.pro" << "CONFIG+=release";

firstProcess->start(qmake, arguments);
firstProcess->waitForFinished();


Now it is supposed that it enters in the proper dir, because QTDIR now is the path to the .pro file. Then I give the absolute path for the qmake, but it doesnt work.

tbscope
24th August 2010, 10:47
There are other errors in your code too
"C:/Qt/2010.01/qt/qmake/qmke.exe"

Please implement a slot that is connected to the error signal.

If all is correct and it still fails, try this:

Open a console window and type the following commands:


cd c:\
mkdir testbuild
cd testbuild
C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro

And see if that gives an error.

locke
24th August 2010, 11:15
Im sorry about the qmke, I changed it triying to find a different behavior.

I did the signal manager and it doest return any error. (when the name qmke.exe was wrong, it returned the signal Failed to start) but now no signal is executed.

If I du the code that you provide, the response is QMAKESPEC has not been set, so configuration cannot be deduced.

And I I do this


C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro -spec C:\Qt\2010.01\qt\mkspecs\win32-g++

Then no message is shown, then the Make file is created under testbuild folder.

So I dont know why I cannot execute it with QProcess

tbscope
24th August 2010, 11:29
If you now try to execute

C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro -spec C:\Qt\2010.01\qt\mkspecs\win32-g++
via a QProcess, you'll notice that the makefile will be generated, but in the folder of your application exe.

If you set the OBJECTS_DIR variable, you can specify where the code should be build.

I guess you'll get into trouble running make from a QProcess too. I don't know how you can cd to a specific directory inside a QProcess object.

Edit: Maybe using void QProcess::setWorkingDirectory ( const QString & dir )

locke
24th August 2010, 11:33
Thanks, I will check your solutions, and will post again

locke
24th August 2010, 11:49
It seems that the OBJECT_DIR is a .pro variable. That means that I need to change the .pro file of all projects that I will build, or it is possible to set that variable in the QProcess or in the qmake as an argument or similar. I havent found anything like that.

tbscope
24th August 2010, 11:57
Try

C:\Qt\2010.01\qt\qmake\qmake.exe "OBJECT_DIR = C:/testbuild" C:\where\your\project\is\MyProject.pro -spec C:\Qt\2010.01\qt\mkspecs\win32-g++

locke
24th August 2010, 12:11
I havent used OBJECT_DIR becasue it only moves the .o files , but not the make files. So I did use QProcess::setWorkingDirectory ( const QString & dir ) before launching the process and I know where the make files are created.

tbscope
24th August 2010, 12:23
Does it work now?

locke
24th August 2010, 12:27
Yes, it creates the makefile files in a located folder. Im triying now to make the second step, with mingw32-make.

locke
24th August 2010, 12:48
For the next people having the same problem.

Do not use "C:/Qt/2010.01/qt/qmake/qmake.exe"

Use "C:/Qt/2010.01/qt/bin/qmake.exe";

Both qmake will create a different makefile and if you choose the first one, you will have problems to build the project.