Search code examples
c++qtqt-creatorqwidget

Qt: QWidget doesn't show when running the application?


My Qt application works fine and, finally yesterday, I manage to create the executable and it is ready for distribution.

Today though, I want to add more features but whenever I try to add/remove a QWidget to the mainwindow.ui on Qt-designer, the changes never displayed when running the application in either release or debug mode !. It always shows me the old version (i.e.: before the modification)

why does this happen and how to fix this ?

UPDATE:

I have to mention that after deploying my application, I changed the application name as follow:

  1. opened Qt-creator, in .pro file, change TARGET value
  2. closed QT-creator, go to source folder and rename it
  3. inside the source folder, renamed the .pro file too

afterward, I realized that whenever I change anything in the Qt-Designer, these changes never take place when running the app.


Solution

  • This is commonly caused by mixing in-source and shadow builds. This most commonly happens, if you let Qt Creator use it's default setting (use shadow build directory), and then also build from command line in the source directly.

    Qt application build generates a bunch of source files, moc_*.cpp (and corresponding object files) and ui_*.h. Now if you have these files both in shadow build directory, and in source directory, then the files in source directory are used first. So you can for example edit your GUI with designer, and have new ui_*.h files generated in the shadow build directory, but never used, because you have stale version in the source directory.

    Solution is to remove all these files from source directory. If you accidentally committed them to version control, be sure to remove them from there also. If you are unsure what you are doing, take backups first.

    One way to clean the source dir is to go there with Qt command line, then run qmake, then run make clean distclean. That should leave it quite clean. Getting rid of shadow build dirs is easier: just delete them, since they only contain generated files.

    Note that you should be using the shadow build dirs, it has many benefits (and the only drawback really is, that if you accidentally pollute the source dir with generated files, you get the problem you have now...).