Results 1 to 13 of 13

Thread: How to code an App that will build QT projects

  1. #1
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. QProcess *firstProcess = new QProcess;
    2. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    3. env.insert("QDIR", "C:\\Qt\\2010.01\\qt"); // Add an environment variable
    4. env.insert("PATH", env.value("Path") + ";C:\\Qt\\2010.01\\qt\\bin");
    5. env.insert("QMAKESPEC", "win32-g++"); // Add an environment variable
    6. firstProcess->setProcessEnvironment(env);
    7.  
    8. QString qmake ="qmake.exe";
    9. QStringList arguments;
    10. arguments << m_pathToProjectFiles + "/MyProject.pro" << "CONFIG+=release";
    11.  
    12. firstProcess->start(qmake, arguments);
    13. firstProcess->waitForFinished();
    To copy to clipboard, switch view to plain text mode 

    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!!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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:
    Qt Code:
    1. /home/myuser/qtdir/someversion/bin/qmake /home/myuser/myproject/myproject.pro
    To copy to clipboard, switch view to plain text mode 
    This will generate the Makefile in the current folder.

  3. #3
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to code an App that will build QT projects

    Doesnt work, I have changed that
    Qt Code:
    1. QProcess *firstProcess = new QProcess;
    2. QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
    3. //Next line was changed
    4. env.insert("QTDIR", m_pathToProjectFiles); // Add an environment variable
    5. env.insert("PATH", env.value("Path") + ";C:\\Qt\\2010.01\\qt\\bin");
    6. env.insert("QMAKESPEC", "win32-g++"); // Add an environment variable
    7. firstProcess->setProcessEnvironment(env);
    8. //Next line was changed
    9. QString qmake ="C:/Qt/2010.01/qt/qmake/qmke.exe";
    10. QStringList arguments;
    11. arguments << m_pathToProjectFiles + "/MyProject.pro" << "CONFIG+=release";
    12.  
    13. firstProcess->start(qmake, arguments);
    14. firstProcess->waitForFinished();
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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:

    Qt Code:
    1. cd c:\
    2. mkdir testbuild
    3. cd testbuild
    4. C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro
    To copy to clipboard, switch view to plain text mode 
    And see if that gives an error.

  5. #5
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro -spec C:\Qt\2010.01\qt\mkspecs\win32-g++
    To copy to clipboard, switch view to plain text mode 
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to code an App that will build QT projects

    If you now try to execute
    Qt Code:
    1. C:\Qt\2010.01\qt\qmake\qmake.exe C:\where\your\project\is\MyProject.pro -spec C:\Qt\2010.01\qt\mkspecs\win32-g++
    To copy to clipboard, switch view to plain text mode 
    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 )

  7. The following user says thank you to tbscope for this useful post:

    locke (24th August 2010)

  8. #7
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to code an App that will build QT projects

    Thanks, I will check your solutions, and will post again

  9. #8
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  10. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to code an App that will build QT projects

    Try
    Qt Code:
    1. 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++
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to tbscope for this useful post:

    locke (24th August 2010)

  12. #10
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  13. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to code an App that will build QT projects

    Does it work now?

  14. #12
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  15. #13
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Replies: 1
    Last Post: 15th June 2010, 14:25
  2. Replies: 1
    Last Post: 14th January 2010, 00:35
  3. new projects ???
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2009, 11:21
  4. build code using vs 2005
    By arunredi in forum Installation and Deployment
    Replies: 3
    Last Post: 14th May 2008, 19:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.