简体   繁体   English

Qt设计师没有更新gui

[英]Qt designer does not update the gui

Someone wrote out a GUI in Qt designer earlier and now I have to modify some small parts (ie add a button/functionality). 之前有人在Qt设计器中写了一个GUI,现在我必须修改一些小部件(即添加一个按钮/功能)。

Premise: I add the new feature/make any modification to the .ui file in Designer. 前提:我在Designer中添加新功能/对.ui文件进行任何修改。 I can go to edit mode and see that this makes changes to the xml format of the .ui file 我可以进入编辑模式,看到这会改变.ui文件的xml格式

Problem: When I build and run Qt, the old version of the .ui is what is shown (without my feature upgrades). 问题:当我构建并运行Qt时,旧版本的.ui就是显示的内容(没有我的功能升级)。 I tried cleaning everything and running qmake, but to no avail. 我试着清理一切并运行qmake,但无济于事。

Any ideas for why this could be happening? 为什么会发生这种情况的任何想法?

I had the same problem and it was solved when I disabled "Shadow Build" in "Projects" mode. 我有同样的问题,当我在“项目”模式中禁用“阴影构建”时,它已解决。

UPD : Still receiving upvotes for this answer makes me sad for 2 reasons UPD :仍然收到这个答案的赞成票让我很难过,原因有两个

  • it is trivial 这是微不足道的
  • the issue is still there after almost 5 years 这个问题在将近5年之后仍然存在

I could solve this problem wihtout change Shadow Build configuration. 我可以在不改变Shadow Build配置的情况下解决这个问题。 In my project I want to build with output files into build-ProjectName-Debug 在我的项目中,我想用输出文件构建build-ProjectName-Debug中

But the QtCreator is not smart to check if are not files moc_FileName.cpp and ui_FileName.h into build directory. 但QtCreator并不聪明,无法检查文件moc_FileName.cppui_FileName.h是否存在于构建目录中。 This problem occur because if these files moc_FileName.cpp and ui_FileName.h are into project directory the QtCreator uses them and does not recognize any modification on .ui files. 出现此问题的原因是,如果这些文件moc_FileName.cppui_FileName.h进入项目目录,QtCreator将使用它们,并且无法识别对.ui文件的任何修改。

The solution to this problem was easy to me: Remove all moc_FileName.cpp and ui_FileName.h from project directory and Rebuild . 这个问题的解决方案对我来说很容易:从项目目录和Rebuild中删除所有moc_FileName.cppui_FileName.h These files will be created into build-ProjectName-Debug and all modifications will be there. 这些文件将被创建到build-ProjectName-Debug中 ,所有修改都将在那里。

When you change a .ui file, someone needs to run uic.exe on the file to generate a header file. 当您更改.ui文件时,有人需要在该文件上运行uic.exe以生成头文件。 For example, for a window called MyWindow.ui , this will generate a file called ui_MyWindow.h . 例如,对于名为MyWindow.ui的窗口,这将生成一个名为ui_MyWindow.h的文件。

This is then what is used when the application is rebuilt. 这是重建应用程序时使用的内容。

You don't specify how you are building or on what OS, so it is hard to help you on that end. 您没有指定构建方式或操作系统,因此很难为此提供帮助。 If you are using Visual Studios it is possible to integrate your .ui files into your projects so that when you change any .ui file, all the generated files will be recreated automatically. 如果您使用的是Visual Studios,则可以将.ui文件集成到项目中,这样当您更改任何.ui文件时,将自动重新创建所有生成的文件。 The same is possible if you are using .pri files. 如果您使用的是.pri文件,则可以进行.pri操作。

In any case, I would run: 无论如何,我会跑:

uic.exe -o ui_yourfile.h yourfile.ui

Please change the names of the files to the ones you are using. 请将文件名更改为您正在使用的文件名。 uic.exe can be found in your Qt bin directory. uic.exe可以在你的Qt bin目录中找到uic.exe

Then once you have the generated header file, try to find where it goes in the build directory. 然后,一旦有了生成的头文件,尝试找到它在构建目录中的位置。 Then rebuild. 然后重建。

我通过clean然后build解决这个问题。我发现,如果我检查了Shadow Build ,qtCreator将使用旧的.obj,除了生成新的.obj,即使ui_xxx.h已被更改,也可以在调试agin时生成.exe我的环境是qt5.5 + msvc2013。

这是帮助我个人的,添加到qmake文件: UI_DIR = $$PWD

I had the same problem and was able to solve it by deleting all the Makefiles in the build directory, then rebuilding from scratch. 我有同样的问题,并能够通过删除构建目录中的所有Makefile,然后从头重建来解决它。 For some reason, these files are not deleted when you run Clean Project from Qt Creator. 出于某种原因,从Qt Creator运行Clean Project时,不会删除这些文件。

Same problem for me. 对我来说同样的问题。 Nothing works until I changed the installation from Qt 5.0.2 (MSVC 2010) to Qt 5.0.2 (mingw). 在我将安装从Qt 5.0.2(MSVC 2010)更改为Qt 5.0.2 (mingw)之前,没有任何作用。 Now it is working again...wired 现在它再次工作......有线

I experienced the same problem: no ui changes appeared after building. 我遇到了同样的问题:建成后没有出现ui变化。 The problem as mentioned above is that the ui files are not getting remade. 上面提到的问题是ui文件没有被重新制作。

Unchecking shadow build solved the problem for me but only once. 取消选中阴影构建解决了我的问题但只解决了一次。 After that I could not see subsequent ui changes again. 之后我再也看不到后续的ui变化了。 So I rechecked shadow build and deleted the existing shadow build folder. 所以我重新检查了阴影构建并删除了现有的阴影构建文件夹。 This works consistently now, as long as I delete all the build files. 现在,只要我删除所有构建文件,它就能一致地工作。 But that's lame. 但那太蹩脚了。 It should be able to detect ui changes and remake the files. 它应该能够检测到ui变化并重新制作文件。

I think this should be logged as a bug in Qt Creator/Designer. 我认为这应该记录为Qt Creator / Designer中的错误。

I deleted all auto gen file in source folder. 我删除了源文件夹中的所有auto gen文件。 when I unchecked shadow build, auto gen file was created in source folder. 当我取消选中阴影版本时,在源文件夹中创建了自动生成文件。 after when I checked shadow build, compiler only use source folder's gen file. 在我检查阴影构建之后,编译器只使用源文件夹的gen文件。 So I deleted all auto gen file(ui_ , moc_ ) and then ui was updated always. 所以我删除了所有自动生成文件(ui_ ,moc_ ),然后ui总是更新。

In my case, the problem was caused by a rename of the .ui file. 在我的情况下,问题是由.ui文件的重命名引起的。 Qt Creator didn't update the #include for the header file "ui_[name_of_ui_file].h" in the .cpp file corresponding to the form. Qt Creator没有更新与表单对应的.cpp文件中的头文件“ui_ [name_of_ui_file] .h”的#include。 Anyway, cleaning up all the "ui_*.h" files in the shadow build folder solved the issue (I guess unchecking "shadow build" in the Project tab would produce the same effect). 无论如何,清理阴影构建文件夹中的所有“ui _ * .h”文件解决了这个问题(我想在项目选项卡中取消选中“阴影构建”会产生相同的效果)。

Have you been playing with the system date or time or they were different from those of your fellow's computer? 您是否一直在使用系统日期或时间,或者它们与您同事的计算机不同? I was changing the time to some hours later for testing purposes (and compiling the project in the meantime) and after restoring it to current time, the compiled files were not updated because they were newer than the compilation time. 我将时间更改为几个小时后用于测试目的(并在此期间编译项目),并在将其恢复到当前时间后,编译后的文件未更新,因为它们比编译时更新。 Running Clean did not delete those files. 运行Clean并没有删除这些文件。 Unchecking the Shadow build option only gave me crashes and an untraceable 0xc0000135 error. 取消选中Shadow build选项只会导致崩溃和无法追踪的0xc0000135错误。 Deleting manually the moc_*.o and *.cpp files with future date/time from the building directory and compiling the whole project again was the solution for me. 手动删除moc _ * .o和* .cpp文件以及建筑目录中的未来日期/时间并再次编译整个项目是我的解决方案。

As mentioned above, the ui files are not getting recreated. 如上所述,ui文件不会被重新创建。 For me, the easiest solution is just hitting Rebuild instead of Build. 对我来说,最简单的解决方案就是点击Rebuild而不是Build。 No need to go into project submenues each time. 无需每次都进入项目子菜单。 As long as your project is not too big, this is OK (apart from this is an anoying bug that qt has for long years now) 只要你的项目不是太大,这是可以的(除了这是qt长期存在的一个令人讨厌的错误)

I had the same problem and then realized that I have modified the .pro file manually: that is I made "illegal" thing - moved mainwindow.ui under DISTFILES (by default all ui files are grouped under FORMS ). 我遇到了同样的问题然后意识到我手动修改了.pro文件:这是我做的“非法”事情 - 在DISTFILES下移动mainwindow.ui (默认情况下所有ui文件都在FORMS下分组)。

Returned back to FORMS and now everything works fine 回到FORMS ,现在一切正常

将以下行添加到.pro文件中

   UI_DIR = $$PWD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM