I'm trying to execute the qmake -project command by doing:
C:\Qt\2010.05\qt>qmake -project
But, it remains there and doesn't get executed. Why is that?
Thanks.
qmake -project without any additional arguments will traverse the current directory recursively, looking for e.g. source, header and UI files to be included in the .pro file. When you run it in a directory containing lots of files (such as Qt folder), it can take a lot of time to go through all of them. Thats why it seems to get stuck.
Related
I have some source code that was built with qmake. Compiling it is supposed to be done with qmake qmakefile.pro.
I'd like to compile it without using qmake. Is that even possible? What would the steps be?
Edit: Here's the .pro file.
Yes, you can compile files without qmake.
You need to get any specific compiler settings from qmake and convert them to the other compiler as necessary.
Or you can convert the contents of the qmake.pro file into a makefile or your IDE's project settings.
If the qmake.pro is not a human readable text file, you will have to launch qmake and retrieve the settings. Otherwise search for a conversion tool.
While it is technically possible to translate the .pro file into something else, I would not advise it.
Why?
QMake does a lot of work behind the scenes.
In the case of the .pro file you referenced (http://pastebin.com/viv204Fv), QMake is invoking meta-tools (uic, moc) to create the code for the UI and adding build rules to compile it. You will need to manually code those in your build script.
-. QMake also solves issues of choosing the right compiler and linker options (including the right include files). You will need to determine them yourself and add them to your build script.
The project is already using Qt, so why not use Qt's build script generating tool, QMake? If you have installed a Qt development environment, you should already have qmake installed.
So I have started a new Qt console project;
everything so far has been working fine. I have eclipse set up with the integration, but i'm not actually using it, i have just included the relevant Qt directories so that my #include <QtGui> calls work.
These have all worked perfectly so far.
i can compile it either using eclipse's build option, or by doing
qmake -project
qmake
make
from the command line. Both work.
the include statements i have; are:
#include <QtGui>
#include <QApplication>
In two different files.
If i add anotherone though, i.e. #include <QSqlDatabase> then eclipse recognises the include, and lets me initialise new variables, and use the QSqlDatabase classes. Everything seems fine - see here - eclipse screenshot
When i build the project though, it decides it can't see the files even though they are all there, see them here in the terminal too. And then eclipse puts red lines everywhere.
If i go into the directory, and attempt to do it all via the terminal, using the qmake -project; qmake; make then i get the same errors.
If however, I go into the .pro file created by qmake -project, and add the line QT += sql, and then do qmake; make, then all is fine and it works.
Why is qmake -project leaving out these files from the project file? I'd really rather not have to go in and manually add that line every time I build it...
Why is qmake -project leaving out these files from the project file?
As far as I know, qmake isn't supposed to replace human programmer. If you want to know WHY it doesn't detect SQL dependency, you can read qmake source code.
I'd really rather not have to go in and manually add that line every time I build it...
It sounds like you're trying to do something weird here. You don't need to call qmake -project before every build.
qmake -project generates initial project - *pro file. Once initial project has been generated, you can tweak it, and add options or some macro magic if you want. Then, using *.pro file, you generate script for your build system (vcproj for windows, makefiles for windows/*nix, nmake make files, etc).
Workflow goes like this:
qmake -project.
Repeat forever:
2.1. modify generated *.pro file to your liking.
2.2 qmake
2.3 Build using your build system. (nmake, make, visual studio, etc.)
To simply "build" all you have to do is #2.3. You call qmake (without -project) switch only if you modified *.pro file.
See qt documentation and tutorials for more info.
I would like to use Qt creator and Cmake together (please, don't ask me about my motivation, accept this as a given.)
I successfully set up Qt creator to use cmake "Cmake": see this, this and this documents regarding how I did that.
I successfully create hello world project, but I can't create files in project,
only add existing files to project tree and after that adding it to cmake list.
Standard operation of Qt creator "Add New..." doesn't work and I can't find why.
Is there anybody who uses Qt creator and "Cmake" together? Is the combination actually possible?
Note: I'm using Qt creator v2.4.1.
You can add files using glob expression in your CMakeLists.txt, like this:
file(GLOB SRC . *.cpp)
add_executable (your_exe_name ${SRC})
Cmake will pick your new cpp files next time you run it and QtCreator will show them in the project browser.
Update
This solution may be useful but as noted in comments - this is not a good practice. Every time somebody add new source file and commit changes, you need to rerun cmake to build all the sources. Usually I just touch one of the CMakeLists.txt files if my build is broken after I pool recent changes from repository. After that make will run cmake automatically and I didn't need to run it by hands. Despite of that I think that explicit source lists in CMakeLists.txt is a good thing, they called thing CMake Lists for a reason.
When you add new files in QtCreator using the "New File or Project..." dialog it only creates the files on disk, it doesn't automatically add the files to the CMakeLists.txt. You need to do this by hand by editing the CMakeLists.txt file.
The next time you build the project, CMake will be re-run, and QtCreator will pick up the new files and show them in the project browser.
I solve this problem that I added new files in standard way (CTRL+N), then added needed files in CMakeLists. After that, right click on project in project tree view and choose option Run CMake. After this, files showed in project list tree. Only build was not enough.
I tested here and happened the same behavior because those options you were asking were really disabled.
Use File -> "New File or Project..." or CTRL+N to add new files and after that add to CMakeLists.txt
I'm adding an updated answer for newer versions of QtCreator (4.x, I don't know precisely which release but at least from 4.7). In the Tools > Options... menu, choose the Build & Run section and then the CMake tab. You will see the Adding Files settings, and you can set it to Copy file paths :
This way, when you want to add a new file to your project, in the Project view, right click on the desired CMake Executable/Library's name and select Add New..., go through the Add dialog, and when you'll validate the dialog, QtCreator will open CMakeLists.txt in the Editor view. Finally, paste the content of the clipboard at the end of the corresponding source file list and save CMakeLists.txt. The CMake project will be parsed, and your new file will show up in the Project view.
Our Qt 4.5 project has a root .pro file that has a SUBDIRS qmake variable. When qmake is called on this root .pro file, it generates a Makefile that calls "qmake && make" for each sub directory.
Now the problem is that for 100+ sub folders, this takes a long time for a one liner change of an other wise up to date project to be detected. (It takes about 13 seconds, waaay to long.) Running make at the root of the project first changes directory to all the sub dirs and runs a do nothing make, until it finds the one directory it actually needs to do work in. (A work around at the moment is to manually cd into the folder that you know you made a code change in, and just run make. For our eclipse environment, this is to clumsy.)
Ideally only the root .pro file should be tweaked, but I will accept answers that hacks the root Makefile as well.
Any suggestions to reduce the trivial make time would be appreciated.
This is a classic argument for the recursive make considered harmful theory: Your problem is that you have dozens of single Makefiles instead of one large one. The only way around the predicament is to refactor the .pro files so that only a single Makefile is generated. I don't know enough about qmake to tell you how to do that, though, sorry.
I have to run the following commands from Qt command prompt: qmake -project then make and this gives me the debug folder with the Moc file.
This is strangely the only way my PC will generate the moc_.cpp file.
So how can I automate the task of these commands so I don't have to use these commands again?
You should not run qmake -project multiple times. The -project option is meant to provide you a template project file for you to edit. An equivalent of what you are doing in an IDE would be creating a "New Project" every time you want to build. After you have the initial project, you should edit it manually, add files when you have new files, etc. If some header file changes, the generated Makefile will notice it and call moc on it to update the moc_*.cpp file automatically. So:
Run qmake -project when you start working on a project.
Run qmake when you want to generate Makefiles.
Run make when you want to build the project.
I guess you have two choices.
call qmake from a parent make process and do a multilevel build. ("Recursive make".)
directly run the meta-object compiler from rules in your makefile
If the second, this page on using the meta-object compiler may help.