What is the meaning of colon (:) operator in “uint isWidget : 1;” in Qt? [duplicate]

不羁的心 提交于 2019-12-01 15:21:00

问题


What is the meaning of colon (:) operator in "uint isWidget : 1;" in Qt? Is "uint isWidget : 1;" equivalent to "uint isWidget(1)"?

The code in Qt is

QObjectData 
{
  public:
     virtual ~QObjectData() = 0;
     QObject *q_ptr;
     QObject *parent;
     QObjectList children;

     uint isWidget : 1;
     uint pendTimer : 1;
     uint blockSig : 1;
     uint wasDeleted : 1;
     uint ownObjectName : 1;
     uint sendChildEvents : 1;
     uint receiveChildEvents : 1;
     uint inEventHandler : 1;
     uint inThreadChangeEvent : 1;
     uint hasGuards : 1; //true iff there is one or more QPointer attached to this object
     uint unused : 22;
     int postedEvents;
     QMetaObject *metaObject; // assert dynamic 
};

回答1:


This is part of C struct notation - you can specify the size of an integer field in bits by using a : numBits after the property name.

I must assume that the same syntax can be used in a C++ class (i'm a C guy, but i'm sure that this is doing the same thing in C++)



来源:https://stackoverflow.com/questions/4825868/what-is-the-meaning-of-colon-operator-in-uint-iswidget-1-in-qt

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