About using an undocumented class in Qt

痴心易碎 提交于 2019-12-22 04:28:24

问题


Is it safe to use the undocumented QObjectUserData class and the QObject::setUserData in Qt?


回答1:


Instead you could look at using QObject::setProperty, this allows you to set not only compile time declared properties, but also dynamic properties which do not need to be declared before use. This allows you to attach arbitrary values to QObjects at run time, similar to user data.




回答2:


In general you should not rely upon undocumented APIs. If you ever plan on upgrading Qt, then don't use it!




回答3:


Undocumented classes are usually internal classes and not part of the Qt API. That means, no guarantee is given that the API won't change or the class is removed completely in the next Qt version. For example, qobject_p.h contains the following warning:

//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists for the convenience
// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp.  This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.

So if you use internal API, you're on your own, and might have to fix/reimplement whatever you were doing when switching to the next Qt version.



来源:https://stackoverflow.com/questions/8260763/about-using-an-undocumented-class-in-qt

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