PDA

View Full Version : Use Qt Creator to create CMakeLists.txt for Widget UI Qt Application



rkraft
27th April 2017, 15:00
Hello,

I am writing a scientific software that I would like to have a GUI. I have been using CMake so far for the compilation process which does not have a UI, just terminal output. For the UI, I want to use Qt and perferablly Qt Creator to help me build the UI. However, I want this to be nicely packaged in a directory and be built using CMake, not Qmake. I have seen lots of posts about how to open a CMakeLists.txt and import a project into Qt Creator, but can it go the other way? So Qt creator makes a standalone CmakeLists.txt for UI application where you don't need QT creator to build? Note: I am aware of the non-Qt option for C/C++ programs in Qt Creator but this is not for a UI, as I understand. Any suggestions would be helpful.

Thanks!

rkraft
27th April 2017, 18:41
I was able to figure this out. What I did was use qt creator to make a seperate UI Widget application. I do all the UI design there and then simply copy the main* files (.ui, cpp) into the source directory of the software I am writing (which is set up for cmake). It seems to be working nicely.

d_stranz
27th April 2017, 19:20
You should not have to copy anything. Having a build system that depends on copy guarantees you'll someday get the build system out of sync with the sources and causes unnecessary compilations of source files that haven't actually changed except that you copied them. Just put the relative path to your real main* files into the CMakeLists.txt file.

I use CMake to build a set of libraries for distribution where the source code for the libraries is scattered over many different directories. I don't copy anything. I just set the sources in the CMakeLists.txt files to point to their actual locations on disk, relative to the CMakeLists.txt current directory.

You still need to manually edit the CMakeLists.txt files to add / remove files. But editing of the .ui and source code files can take place with Qt Creator or any other code development IDE you want.