QT -- 对数据的判断(总结)

一、判断Mat是否为空

if(img.empty())return -1; //是否加载成功

if(!img.data)return -1;//判断是否有数据

二、判断QImage、QPixmap是否为空

if(m_currentImage.isNull()) return; 

三、QString判断空

isEmpty

Returns true if the string has no characters; otherwise returns false.

 QString().isEmpty();            // returns true
 QString("").isEmpty();          // returns true
 QString("x").isEmpty();         // returns false
 QString("abc").isEmpty();       // returns false

isNull

Returns true if this string is null; otherwise returns false.

 QString().isNull();             // returns true
 QString("").isNull();           // returns false
 QString("abc").isNull();        // returns false
原文地址:https://www.cnblogs.com/zzzsj/p/14768167.html