Qt文档阅读笔记-Q_ASSERT的另外一总用法(大佬用法)

刚刚看到文档里面有个Q_ASSERT,好玩的用法!

普通人的用法如下:

#include <QApplication>
#include <QGraphicsLineItem>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QList>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QList<QGraphicsItem*> list;

    for(int i=0;i<10;i++){

        list<<new QGraphicsLineItem;
    }

    QGraphicsDropShadowEffect *effect=static_cast<QGraphicsDropShadowEffect*>(list[0]->graphicsEffect());

    if(effect==NULL){
        qDebug()<<"The effect pointer is NULL!";
        return 0;
    }
    QList<QGraphicsItem*>::iterator it=list.begin();
    while(it!=list.end()){
        delete *it;
        it++;
    }
    list.clear();

    return a.exec();
}

运行截图如下:

 

文档里面的Qt代码,是这样的模式,简直阔怕啊!爽得一笔啊!!!

#include <QApplication>
#include <QGraphicsLineItem>
#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QList>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QList<QGraphicsItem*> list;

    for(int i=0;i<10;i++){

        list<<new QGraphicsLineItem;
    }

    QGraphicsDropShadowEffect *effect=static_cast<QGraphicsDropShadowEffect*>(list[0]->graphicsEffect());

    Q_ASSERT(effect);

    QList<QGraphicsItem*>::iterator it=list.begin();
    while(it!=list.end()){
        delete *it;
        it++;
    }
    list.clear();

    return a.exec();
}

运行截图如下:

 

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页