ptr->alloc == 0); Q_ASSERT(data.ptr->capacityReserved == 0); Q_ASSERT(data.ptr->size >= 0); return data; } 而这个枚举int和字符串的关系其实在元对象系统moc时已经被确定: moc_customenum.h struct qt_meta_stringdata_CustomEmun_t { QByteArrayData data[6]; char stringdata0[66]; ...
void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::AllocationOptions options) { Q_ASSERT(asize >= 0 && asize <= aalloc); Data *x = d; const bool isShared = d->ref.isShared(); if (aalloc != 0) { if (aalloc != int(d->alloc) || isShared) {...
示例2:运行宏Q_ASSERT和Q_ASSERT 宏Q_ASSERT和Q_ASSERT常用来检测程序错误,下面例子使用了这两个宏: 复制 char *alloc( int size ){Q_ASSERT( size>0 ); //如果size>0表达式不成立,打印警告信息char *p=newchar[size];Q_CHECK_PTR( p ); //如果指针p为空,打印警告信息return p;} 1. 2. 3. 4....
实际真正的底层是QArrayData类 struct Q_CORE_EXPORT QArrayData{QtPrivate::RefCount ref; //基类实现原子变量的递增递减int size;uint alloc : 31;uint capacityReserved : 1;qptrdiff offset; // in bytes from beginning of headervoid *data() {Q_ASSERT(size == 0 || offset < 0 || size_t(offs...
char*alloc(intsize) { Q_ASSERT(size>0); char*p=newchar[size]; Q_CHECK_PTR(p); returnp; } 1. 2. 3. 4. 5. 6. 7. 如果你定义了QT_FATAL_ASSERT标记,Q_ASSERT将会调用fatal()而不是warning(),所以一个错误声明将会导致在打印错误消息后使程序退出。
QT_TRY {// allocate memoryx = Data::allocate(aalloc, options);Q_CHECK_PTR(x);// aalloc is bigger then 0 so it is not [un]sharedEmpty#if!defined(QT_NO_UNSHARABLE_CONTAINERS)Q_ASSERT(x->ref.isSharable() || options.testFlag(QArrayData::Unsharable));#endifQ_ASSERT(!x->ref.isSta...
char*alloc(intsize) { Q_ASSERT(size>0);char*ptr=newchar[size]; Q_CHECK_PTR(ptr);returnptr; } Q_ASSERT(),Q_ASSERT_X(), andQ_CHECK_PTR() expand to nothing ifQT_NO_DEBUGis defined during compilation. For this reason, the arguments to these macro should not have any side-effects....
char *alloc( int size ) { ASSERT( size > 0 ); char *p = new char[size]; CHECK_PTR( p ); return p; } 如果你定义了标志QT_FATAL_ASSERT, ASSERT将会调用fatal()取代warning(), 所以一个失败的断言将会导致程序在输出错误信息后退出. ...
int r = uv_udp_bind(udp_socket_.get(), (const struct sockaddr *) &addr, 0); if (r) { qDebug() << "Failed to bind UDP socket: " << uv_strerror(r); } r = uv_udp_recv_start(udp_socket_.get(), allocBuffer, onUdpReadStatic); ...
inline QString::QString(const QString &other) noexcept : d(other.d) { Q_ASSERT(&other != ...