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. QListWidget current index/item

QListWidget current index/item

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 440 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.
  • naaxN Offline
    naaxN Offline
    naax
    wrote on last edited by
    #1

    Hello guys

    I changed ComboBox into QListWidget but I can't resolve this problem.

    Before was:
    Kcals[0]+=ItemKcals[ItemMap[ui->comboBox->currentText()]];

    I tried:
    //double Kcals[]
    Kcals[0]+=ItemKcals[ItemMap[ui->qListTest->currentIndex()];
    Kcals[0]+=ItemKcals[ItemMap[ui->qListTest->currentIndex()];

    //mainwindow.cpp:78: error: no viable overloaded operator[] for type 'QMap<QString, int>'

    Can you help me with how to read the current Index or Item to this variable Kcals? Before I used QMap and that worked, but I dont have any more ideas.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi

      QString text;
      if (ui->listWidget->currentItem())
         text = ui->listWidget->currentItem()->text();
      

      Do note that currentItem() might be NULL so you must check it or your app will crash.

      naaxN 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi

        QString text;
        if (ui->listWidget->currentItem())
           text = ui->listWidget->currentItem()->text();
        

        Do note that currentItem() might be NULL so you must check it or your app will crash.

        naaxN Offline
        naaxN Offline
        naax
        wrote on last edited by
        #3

        @mrjj said in QListWidget current index/item:

        text = ui->listWidget->currentItem()->text();

        That's works! Thanks man!

        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