Qt Creator problem. UI changes not showing when pr

2020-06-19 03:07发布

问题:

I'm making changes to a form in Creator but when I build the changes are not being "refreshed". I've gone so far as to remove every element from the form and get rid of every stylesheet but when I build the project I get the same result; as if I had never made a change at all. What gives? Am I missing something obvious? (obvious to everyone but me.. obviously)

回答1:

I guess you're using QtCreator 2.0? I found the same strange issue. You have two options:

  • Remove the ui_{the_name_of_design}.h from the project's build dir. Then run qmake again.
  • make clean or Build → Rebuild All

But the second option even doesn't help with me. By the way that's why is good to use a different build dir than that where the sources are. If some changes don't appear to be applied, just delete the content of build dir, and everything goes fine as well.

Cheers



回答2:

Most likely cause if that your make procedure is not noticing the changes in the .ui file, and so it is not calling the uic tool. Try to do a make clean to see if it helps, and check your build log to see if uic is being called.



回答3:

For me, the solution was to change the BuildDirectory to the same directory where the code is, instead of the **-build-desktop directory.



回答4:

I stumbled upon this issue as well and one thing I noticed was that my program was still running in the background without me knowing. Ending the task through task manager fixes it and you can make changes again.



回答5:

A few suggestions:

  • Perform a make distclean.
  • Use a shadow build directory. Building “inside” the source code is not advised.
  • Check your computer’s clock and the date and time of your files.


回答6:

This thread is a little dated but since I got caught up in the same problem I thought I would share how I resolved this. I've been incrementally building up a ui with designer under QtCreator 2.4.1/Qt 4.8.1 using a poor man's source control approach: snapshots. At one point I inadvertently created a non-shadowed build project. In a subsequent snapshot I reverted the project back to shadow build and at that point new widgets added in the ui form were no longer being recognized in the build. Solution: Delete stale ui_.h files from the source directory. Delete make and ui_.h files from your shadaow build directory. Rebuild Latest generated ui_.h files will reappear in the shadow build directory. No copies of ui_.h files appear in the source directory indicating that the stale files were taking precedence in the build order. Not obvious.



回答7:

I have this problem and i solve it by changing the project path. I had stored the project in my flash memory when i had this problem, then i copy the project folder and it's build folder also in the Desktop and open it with QtCreator and the problem was solved.



回答8:

Problem is indeed stale generated files in project source directory. This can happen both with genrated ui_*.h files, as well as with moc_*.* files. Below is not covered by existing answers, so here we go:

To remove generated files from the project source directory, without affecting Qt Creator settings or current shadow build directories, there are two principal ways, which can also be combined for extra coverage.

  1. Go to Qt command prompt, go to project source directory and run these commands:

    qmake -r
    make clean
    make distclean
    

    1st one will recursively create makefiles. 2nd one will remove all files produced by building the project. 3rd one will remove the makefiles again. Then continue using shadow build from Qt Creator as before.

    The problem with this is, it will leave files which are not part of the project. So if some files have been removed from project, related generated files may remain, and cause trouble if files with same name are added back. So even after this it is good idea to verify no ui_* or moc_* files remain, if you know you have removed files from project.

  2. Use your version control software to first commit or stash/shelve all uncommitted changes, and then remove all unversioned (also otherwise ignored) files. For some version control software this may not be easy as git clean -dxf (beware, that will also lose uncommited changes and Qt Creator's custom project settings), and in that case it may be easier to just remove project source directory and get a clean checkout.

    The problem with this is, if some generated files have accidentally been added to project, they will not be cleaned up with this. So it may still be a good idea to do the step 1 above too.

Above steps should be in sync so that after step 1, any files in source directory (except Qt Creators's projectname.pro.user and possible *~ backup files) should be under in version control.