Qt segmentation fault unless I rebuild

浪尽此生 提交于 2019-12-23 03:51:53

问题


I'm working on a Qt project and often when I make a bunch of changes and build, when I run the program I get a random segmentation fault somewhere in the Qt framework.

To fix it I have to rebuild and then it goes away.

I found another person who had this issue and they received this answer:

from: Segmentation fault in Qt application framework

This makes it sound as though your build system isn't recognizing a dependency and that a change to that class definition isn't triggering a rebuild of something that should be recompiled when the definition changes.

Make sure class LevelIndicator is defined in exactly one place (generally that would be a header file that gets included by whatever modules need to use a LevelIndicator object). Also make sure that any global/static instances of LevelIndicator objects are following the one definition rule.

So that makes sense to me, however each class is defined in only one place, with #ifndef guards to prevent double inclusions. So how can I avoid this?


回答1:


Usually such errors happen if you change header files but some source file isn't rebuilt, e.g. by adding members to structs/classes. QMake's dependency handling is peculiar in that regard. If you include headers from other directories using the INCLUDEPATH variable, you must also add the directory to the DEPENDPATH variable to have them "monitored" for changes. Otherwise changes in the INCLUDEPATH directories won't trigger rebuilds in the current directory. It should look like this:

 INCLUDEPATH += ../somelib/include
 DEPENDPATH += ../somelib/include

Rule of thumb: If you see a INCLUDEPATH directive pointing to a path inside your project without corresponding DEPENDPATH directive, almost always that's wrong.

See also my answer to a similar question.



来源:https://stackoverflow.com/questions/5515303/qt-segmentation-fault-unless-i-rebuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!