Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] IndexOf() in QVariantList
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] IndexOf() in QVariantList

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ningu
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ningu
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved