Need Help - passing 'const KanaData' as 'this' argument of 'int KanaData::KanaVowelCount(int)' discards qualifiers



  • I'm writing a flash-card like program to teach the Japanese Kana Alphabet but I can't get past this error. I thought maybe it was Qt Creator since I've had similar problems before but clearing the project and rebuilding it didn't fix it this time.

    This is the error message

    kanamodel.cpp:16: error: passing 'const KanaData' as 'this' argument of 'int KanaData::KanaVowelCount(int)' discards qualifiers

    I have scoured the internet and Qt Help but am lost - there is nothing constant, I am using QMap in one function but I'm not using .at() or .value(), I'm using the Square-Brackets "[]". I've checked the functions and none of them return constant values. I've even tried to call the function several different ways and all produce the exact same error message.

    These are the function calls:
    @int KanaModel::columnCount(const QModelIndex& parent) const
    {
    return modelData.KanaVowelCount(KanaSet_Hiragana); // KanaSet_Hiragana is enum
    }@

    @int KanaData::KanaVowelCount(int kSet)
    {
    if(!KanaSetExists(kSet)) return 0;
    return data[kSet].size();
    }@

    @bool KanaData::KanaSetExists(int kSet)
    {
    if(data.contains(kSet)) return true;
    return false;
    }@

    Thanks in advance!



  • I figured it out. The problem was right in front of me - the Column Count function was constant but my function wasn't - making my function constant fixed all the relevant errors to this post.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.