即使两个字符串不同,QString :: compare也会返回0

时间:2017-03-06 14:48:24

标签: qt qstring

当我提供QString :: compare与两个字符串时:

for(int i = 0; i < ui->tableWidget->rowCount(); i++
{
    // assuming searchDialog is a custom-made class with method getResultMap
    QMap<QString, int> result = searchDialog->getResultMap();
    QString phrase = result.keys().at(0);
    int itemFound = 1;    

    if(itemFound == QString::compare(ui->tableWidget->item(i, searchByColumn)->text(),  
                                                       phrase, 
                                                       Qt::CaseInsensitive)) == 0)
    {
         // Enters here even though the strings differ
    }
}

即使字符串如下,它总是返回0:

"Car"
"Horse"
"Human"

然而,当我这样做的时候:

if(ui->tableWidget->item(i, searchByColumn)->text() == phrase)
{
    qDebug() << "Entered the condition";
}

比字符串看起来不同(它不会进入条件)。

可能的原因是什么?

0 个答案:

没有答案