3

I have a Qt5 project, using CMake with AUTOUIC, AUTOMOC, and AUTORCC.

My problem is that if I change one of the .ui files, I expect UIC to run and produce the corresponding ui_XXX.h file. It doesn't. I have the .ui files listed in my add_library(... Foo1.ui Foo2.ui) declaration.

This is on Windows with Visual Studio 2019. I am using the VS solution file produced my CMake. As far as I can tell, the only time Auto UIC runs is if it is building the library; touch any source file, and everything builds as expected. Touch just a .ui file and build, and it doesn't build anything.

Building the application on Linux works as expected.

We just migrated the project to CMake for a common build system between Windows and Linux and quirks like this are annoying some people on the team and we would like to resolve them.

Kevin
  • 16,549
  • 8
  • 60
  • 74
James
  • 148
  • 1
  • 7
  • Does creating a UIC rule for each individual `.ui` file using [`qt5_wrap_ui()`](https://doc.qt.io/qt-5/qtwidgets-cmake-qt5-wrap-ui.html) solve the issue? Have you tried this? – Kevin Feb 19 '20 at 16:42
  • I tried qt5_wrap_ui() on a small project with a few .ui files and it seems to work OK with minimal testing. We have a large library with about 350 .ui files and were hoping the AUTOUIC stuff would just work as no one wanted to maintain a CMake file with all those .ui files. – James Feb 19 '20 at 17:00
  • I found an issue for this in the CMake issue tracker (see answer), but unfortunately it has not yet been fixed. If you choose to use `qt5_wrap_ui()`, you could go to the directory containing the `.ui` files, and use the command `dir /b /a-d` in Windows `cmd` prompt to list all the file names and copy/paste the output into your CMake. Hope this helps! – Kevin Feb 19 '20 at 17:18

1 Answers1

1

This was a known CMake issue, and was fixed by this merge request (5999). The issue mentions Visual Studio 2017 specifically, but the problem will be the same for other Visual Studio generators.

If you can't update to the version where it was fixed, one work-around is to use the qt5_wrap_ui() command instead of relying on CMAKE_AUTOUIC. This way, a UIC rule is created for each .ui file explicitly listed:

qt5_wrap_ui(MY_LIB_UI_FILES Foo1.ui Foo2.ui ...)
add_library(MyLib 
    # ... 
    ${MY_LIB_UI_FILES}
)
starball
  • 20,030
  • 7
  • 43
  • 238
Kevin
  • 16,549
  • 8
  • 60
  • 74