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. Set value to multiple Qlabels using 1 ComboBox
Forum Updated to NodeBB v4.3 + New Features

Set value to multiple Qlabels using 1 ComboBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 292 Views 2 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.
  • L Offline
    L Offline
    Lightshadown
    wrote on last edited by
    #1

    Hello, im trying to set the value from a combobox to multiple Qlabels, the idea is to populate the QcomboBox with all the values, then according to the number, (ejem 15.6) the corresponding label should change the problem is, theres too many of them to simply use a switch of something similar, but all the names of the labels are similar, HumSec_val156 corresponds to 15.6 the main idea was to use

    Silo* silo = new Silo;
    QString number = widget.QComboBox->currentText();
    QString nameOfLabel = "HumSec_val"; 
    nameOfLabel.append(QString::number(number));
    silo->findchild<QLabel*>(nameOfLabel)->setText(valuefromCombobox);
    

    but everytime it simply return an empty string, i did try using somthing simplier like

    widget.nameOfLabel->setText(valuefromComboBox);
    

    but nameOfLabel its just a qstring so i can mix it with the code generated from designer. Any idea what can i do? do i need to create something like a scoped enum or similar?

    deductions.png

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

      Hi
      Your idea should work but Im wondering if you checked it finds the expected QLabel in the silo.
      Do you use setObjectName when you create the labels ?

      also it does have non 0000
      in nameOfLabel.append(QString::number(number));
      ?

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        One simple way to do that is to have a dict which keys are the value you want to change and the value is the widget you want to update.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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