空か確認
解説
isEmpty(),empty()はQListの要素が空かどうかを判別します.isEmpty()とempty()の処理内容は同じです.
定義は以下の通りです.
bool QList::isEmpty () const
bool QList::empty () const
要素数が0の時にtrueを返し,そうでないときにfalseを返します.
empty()はSTLに対する上位互換のために存在します.
使用例
#include <QTextCodec>
#include <QTextStream>
#include <QList>
int main(int argc, char *argv[]) {
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QTextStream out(stdout);
QList<QString> lst;
lst << "A" << "A"; // lst = ("A", "A")
out << lst.isEmpty() << "\n";
lst.clear(); // lst = ()
out << lst.isEmpty() << "\n";
return 0;
}
出力
0
1
最終更新:2011年09月18日 19:23