[SOLVED] IndexOf() in QVariantList



  • Hi,

    I have a QVariantList of QStrings and doubles similar to this
    @QVariantList list;
    list << "hello" << 80 << "bye" << 120; @

    When I try
    @list.indexOf("hello")@

    I get -1 (should be 0).

    I have tried
    @list.indexOf(QVariant("hello"))@

    but I get the same value. How could I find the index of a QVariant(QString) in a QVariantList?

    Thanks!


  • Moderators

    the method's you've posted work fine for me.
    @
    QVariantList list;
    list << "hello" << 80 << "bye" << 120;
    qDebug() << list.indexOf("bye"); //returns 2
    @

    What Qt version are you using?



  • oops, you're right, this code works. I was trying to simplify my actual code, but I hadn't tried it. My real code is a bit more complicated.

    I was posting it when I realized I was passing a wrong string argument to indexOf. I was asking it to find "backroundThreshold" and should've been "backgroundThreshold:NUMBER". Hence the -1.

    Thanks for you help!


Log in to reply
 

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