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. Using variables to acces UI
Forum Updated to NodeBB v4.3 + New Features

Using variables to acces UI

Scheduled Pinned Locked Moved Unsolved General and Desktop
ui objectvariable
2 Posts 2 Posters 896 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.
  • P Offline
    P Offline
    plymouth21
    wrote on 17 Apr 2016, 12:35 last edited by
    #1

    HI Guys,
    I'm new to Qt

    I have about 50 buttons in my UI, and I need to modify them if the certain condition is met,

    void aaa::on_push_button1_clicked()
    {
    ui->pushButton_00->setEnabled(true);
    }

    this one works well, but so I wil have to manually check for every button, so I want to replace pushButton_00 with a variable, but I can't get it to work

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 17 Apr 2016, 13:30 last edited by mrjj
      #2

      Hi and welcome
      There is a special sender() in a slot you can use to know which button was the sender of
      the clicked() signal

      void aaa::on_push_button1_clicked()
      QPushButton *butt=qobject_cast<QPushButton *> ( sender() ) ;
      if (butt) {
      }

      that way u can use a variable and not ui->NAME

      All you buttons should be connected to same slot then.

      You could do that after setupUI()

      QList<QPushButton *> list = this->findChildren<QPushButton *>();
      foreach(QPushButton *b, list) {
      connect(b, XXX
      }

      1 Reply Last reply
      0

      1/2

      17 Apr 2016, 12:35

      • Login

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