ファイルからの単語を含む qbytearray を反復処理します。各単語を特定の単語と比較します。
明確にしていただきありがとうございます。その場合1を to に変換してQByteArrayからQString、それを個々の単語に分割して、簡単に比較できるようにします。
// QByteArray is implicitly convertible to QString
QString allWords = yourByteArray;
// split the string at each whitspace or newline
QStringList aWordlist = allWords.split(QRegExp("[\s\r\n]"), QString::SkipEmptyParts)
for (QStringList::iterator it=aWordlist.begin(); it != aWordlist.end(); ++it)
{
// it points to the next word in the list
if (*it == word)
{
...
}
}
1ファイルの内容をバイト配列として受け取るという事実を変更できないと仮定しています。QFileそれ以外の場合は、a を開いて、そこから内容を読み取る方がよいでしょう。
この場合、どのように値を比較できますか?
QString documentationによると、反復せずQStringに比較できます。QByteArrayしたがって、次のように簡単に言えます。
QString word("Hello");
QByteArray bytes("hi");
if (word == bytes)
{
...
}