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. Real time push button click check
Qt 6.11 is out! See what's new in the release blog

Real time push button click check

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 379 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.
  • K Offline
    K Offline
    knyitra
    wrote on last edited by
    #1
    //Constructor
    connect(btn, &QPushButton::clicked, this, &MainWindow::add);
    
    
    void MainWindow::add() {
        QPushButton* btn = new QPushButton(scrollAreaSlider);
        ......
        listBtn.push_back(btn); //it is a QList, and it is a private variable
    }   
        
    void MainWindow::load(QString str) {
        ...........
    }
    

    In real time, if the listBtn element has been clicked I want to call another function called load, and do something with the listBtn clicked button text.

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

      Hi,

      You can connect a lambda to call your load function with the button text.

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

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You can connect a lambda to call your load function with the button text.

        K Offline
        K Offline
        knyitra
        wrote on last edited by
        #3

        @SGaist

        Okey so, I have to go thorugh each button with foreach, and using lambda function.

        JonBJ 1 Reply Last reply
        0
        • K knyitra

          @SGaist

          Okey so, I have to go thorugh each button with foreach, and using lambda function.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @knyitra
          Yes to lambda. You only need to foreach if you want to connect in retrospect; if you do the connect()s immediately after you create each QPushButton as you go along you don't need to revisit them.

          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