How to code an App that will build QT projects
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
Code:
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);
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!!
Re: How to code an App that will build QT projects
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:
Code:
/home/myuser/qtdir/someversion/bin/qmake /home/myuser/myproject/myproject.pro
This will generate the Makefile in the current folder.
Re: How to code an App that will build QT projects
Doesnt work, I have changed that
Code:
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";
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.
Re: How to code an App that will build QT projects
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:
Code:
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.
Re: How to code an App that will build QT projects
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
Code:
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
Re: How to code an App that will build QT projects
If you now try to execute
Code:
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 )
Re: How to code an App that will build QT projects
Thanks, I will check your solutions, and will post again
Re: How to code an App that will build QT projects
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.
Re: How to code an App that will build QT projects
Try
Code:
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++
Re: How to code an App that will build QT projects
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.
Re: How to code an App that will build QT projects
Re: How to code an App that will build QT projects
Yes, it creates the makefile files in a located folder. Im triying now to make the second step, with mingw32-make.
Re: How to code an App that will build QT projects
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.