About using an undocumented class in Qt

2020-08-20 09:02发布

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

标签: c++ qt qt4
3条回答
Explosion°爆炸
2楼-- · 2020-08-20 09:31

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

查看更多
ら.Afraid
3楼-- · 2020-08-20 09:34

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.

查看更多
叼着烟拽天下
4楼-- · 2020-08-20 09:34

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.

查看更多
登录 后发表回答