Autocomplete in Qt Creator: how to add header files for a cmake project - qt

If I am making a Qt Creater project using cmake, rather than qmake, how can I tell Qt Creator where to look for header files for autocompletion? In CMakeLists.txt, I can specify where to look for heading in compilation, but Qt Creator will not read this until I build the project.

You can make headers show up in CMake by including them in the sources list for a target you're building, alongside the source files. This works for files that are part of your project.
For header files somewhere on your system where the compiler can find them, I'd guess that running CMake (to generate the Makefile) should be enough for Qt Creator to find them.

Related

How to properly add a .qrc file to a QT 6 widget app with Cmake as building system?

I'm trying to use a .qrc file to store icon images for my QT application but the Resources.qrc file never appears in resource selection. I'm using CMake as building system and 6.3.1 QT version.
When simply adding Resource.qrc to source files with AUTORCC ON file never appears in project tree, when specifically written as project source in CMakeLists it appears in project tree, but never in resource selection when I'm trying to set ToolButton icon, no matter if I add prefix and images or not.
When AUTORCC is OFF and qt_add_resources(PROJECT_SOURCES Resources.qrc) added to CMakeLists, Resources.qrc file appears in CMake modules folder in a tree, but again, never in resource selection.
There are a lot of guides about .qrc when QMake is building system, but I hardly found anything about same thing with CMake, and none of them helped me, maybe I couldn't understand them properly. Sorry for possible mistakes, I'm new in programming and english isn't my native language. I'll be grateful for any help.

How to use qt creator for non qt, non cmake project?

I want to use qt creator for modifying a project that just uses makefiles. How i can do it? Right now i can just open project files one by one and there is no auto code completion or other advantages of ide. My main concern is use the ide over ssh actually.
I tried open all folder but it didnt work too.
You can use Qt Creator for non-Qt projects, but it will always assume you want to use qmake, CMake, or QBS as your build system. It's not going to read your plain Makefiles and recognize what source files you are using.
In the New Project wizard, you can select non-Qt application. I recommend selecting qmake as your build system, which will create a .pro file, even if you won't end up using it. Then after it creates the project, go into your Project settings under Build Steps. You can delete the built-in steps and add your own custom build steps to do whatever you want. Call make or whatever. Do the same for the Clean Steps.

how build the qt project itself using qtcreator

Update:
Because this was partly to have a project to code-browse the whole of qt, here is a much better way to do this: Code Browser by Woboq for C & C++
This even lets you browse into the includes outside the project like the system includes or the standard library.
Old Post:
My question is about Qt project in git://code.qt.io/qt/qt5.git repository. I checked out version 5.12.
My assumption is that qtcreator knows the qmake file but nothing about the configure command. Hence
I used the configure command to prepare the build in a shadow build directory
In QTCreator I opened qt.pro located in the git workspace
QTCreator opens the build settings dialog and I import them from the shadow build directory
Finally I click build in QTCreator.
But the compile window stalls when asking me for input. Qmake asks me about the licence type I want to choose. I had answered that already in the configure phase and even if I would agree to answer the question again, there is no prompt function in qtcreator's compile output window. Where did I go wrong?
If I forget about QTCreator and call make in the shadow build directory, then everything is build fine and without any licensing questions. When I then import the shadow build directory into a QTCreator, then I can build in QTCreator. But then I clicked Run qmake out of curiosity and I was back to square one, i.e. compile window asks me for input again and stops there forever.
Apart from my specific question I found no general documentation about building the qt libraries using QTCreator. I only find descriptions about compiling projects that use the Qt library.
Qt is not really meant to be compiled from within an IDE. However, this does not mean it's impossible to do. There are two ways to archive this:
First approach: Add the developer build as custom kit:
Run the configure script (and add the -developer-build option)
Open QtCreator and go to "Tools > Options > Kits"
Go to "Qt Versions" add press "Add" - select the qmake executable generated by the configure script. Then hit "Apply"
Go to "Kits" and press "Add" - Make shure to select the correct compilers and debugger and select the previously create "Qt Version". Press "Ok"
Open the top level .pro file in QtCreator and choose the previously created Kit. QtCreator will now use the correct qmake executable
This is the "proper" way to go. You can now use the project as any normal project, including changes to pro-files. Also, QtCreator now correctly detects the build directory, so you won't have to change that, even when opening one of the modules.
Second approach: Use as a normal project without qmake:
Run the configure script (and add the -developer-build option)
Run make qmake_all in the same terminal to let Qt prepare all makefiles, create headers etc.
Open the top level .pro file in QtCreator. You can choose any kit.
Go to Project > Your Kit > Build and disable the "qmake" step (the first of the default 2 steps)
Change the "build directory" to be wherever you built Qt - either a shadow build or the source directory
Hit Build and QtCreator will invoke make only, archieving the same behaviour as running make from the console.
This is kind of a workaround and I would not recommend using it for a full Qt build, unless the first approach does not work for you for whatever reason.
This can also be useful if you only want to make changes to a single Qt module, without compiling the whole Qt framework, i.e. you can clone one of the submodules and use your "existing" qmake on it instead of compiling QtBase (in that case, you skip step 4)
Final notice: When I tried opening the whole Qt-Project, QtCreator crashed on my system because the project was to big to handle. I would recommend you to only open one of the modules within the super repostitory, i.e. "qtbase", "qtdeclarative", etc.

Qt Creator won't open CMake C++ Project in OSX

I'm trying to work on an open-source project in Qt Creator on OSX. When I open the CMakeLists.txt like other CMake projects in Qt Creator it doesn't open the project. No folders, source files, not even the CMakeList.txt shows up in Qt Creator, just a completely blank project.
What could cause a project to do this?
Edit: the project opens properly in Ubuntu. It shows the CMakeLists.txt, source files, and everything. It even builds properly when I CMake in the command line on OSX. Qt Creator in OSX just does not open this project properly.
Eit 2: My build settings are completely empty too. There are no General Messages or messages of any kind.
Open your Preferences (Cmd+, on Mac) and go to the Build & Run and then CMake tab, do you see any CMake version listed there? For me, I have to add a manual entry because it doesn't automatically find my CMake. My manual entry is set to /Applications/CMake.app/Contents/bin/cmake so compare that with what you have in your settings.
Then restart Qt Creator and reopen your project. Go to Build & Run again and make sure the Kit you have selected for your project has a CMake Tool set (should be automatic if you have just the one CMake entry listed on the CMake tab).
Background Information
It looks like you are using Qt Creator 4.0. With that version, they changed a number of things related to how CMake projects are handled. When you first open a project, it won't create the build directory if it doesn't exist. Instead, it will run CMake in a temporary directory. This would be shown in the General Messages output pane if you had it open. Once you manually create the output directory as it appears in your project's Build Settings, Qt Creator will switch to running CMake in there instead. There's no indication this is happening apart from what is logged in the General Messages output pane, even if there's a problem with your CMakeLists.txt.
In your case, if there's genuinely nothing appearing in your General Messages output pane and CMake is working fine from the command line, that suggests something may be wrong with your Qt Creator settings.

Convert project Qt to file .exe for window

Hello i'm a young develop on Qt. I want to know that can we convert project Qt (header, source, form, resource) to a file can run without Qt Creator? And how can we convert it to a file executable on window (.exe)?
The compiler is responsible for making an executable out of the source code. This has nothing to do with Qt.
When you start a program from the QtCreator an executable file is built by the compiler, then started. Have a look in your project folder to find that .exe file.
You dont have to do anything special. Each Qt project has a .pro file that is used for compiling. You need to use qmake on the command line with the .pro file as input. This will generate a makefile that you can then give to nmake.exe (if using Visual Studio compilers) or mingw-make (if you are uisng mingw compilers) to build. These steps will compile your source code into the .exe. Look through documentation of qmake to know more. Qt Creator also does the same steps and you can check out the buildlog in Qt Creator to see it working.
Yes, the exe file that you compile with Qt Creator or alternatively some other IDE or compiler is technically all you need to run the project from there on, except you need to have the linked Qt libraries somehow available to the executable. This is especially important if you plan to run it on a machine different from the one you developed it on. See the Qt documentation on Deploying Qt Applications for other details you may need to consider in that case.

Resources