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. How to auto click pushButton in ui after running the mainwindow ?
Forum Updated to NodeBB v4.3 + New Features

How to auto click pushButton in ui after running the mainwindow ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 773 Views 3 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on last edited by
    #1

    How to auto-click pushButton in UI after running the main window

    main. CPP

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QApplication>
    #include "Aes.h"
    #include <QThread>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
    

    UI Page :

    Capture.JPG

    Thanks in advance

    M JonBJ 2 Replies Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      How to auto-click pushButton in UI after running the main window

      main. CPP

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QApplication>
      #include "Aes.h"
      #include <QThread>
      #include <QDebug>

      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          MainWindow w;
          w.show();
          return a.exec();
      }
      

      UI Page :

      Capture.JPG

      Thanks in advance

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @Ramkumar-Mohan
      If I understand you well, you can simulate a click with:

      [slot] void QAbstractButton::click()
      Performs a click.
      All the usual signals associated with a click are emitted as appropriate. If the button is checkable, the state of the button is toggled.
      This function does nothing if the button is disabled.
      See also animateClick().

      1 Reply Last reply
      0
      • Ramkumar MohanR Ramkumar Mohan

        How to auto-click pushButton in UI after running the main window

        main. CPP

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QApplication>
        #include "Aes.h"
        #include <QThread>
        #include <QDebug>

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            MainWindow w;
            w.show();
            return a.exec();
        }
        

        UI Page :

        Capture.JPG

        Thanks in advance

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

        @Ramkumar-Mohan
        It is an odd thing to want to do to actually cause an "auto click". Rather, since that would just emit the signal to cause any attached slot(s) to run, simply call the desired slot method(s) yourself explicitly in code.

        Ramkumar MohanR 1 Reply Last reply
        0
        • JonBJ JonB

          @Ramkumar-Mohan
          It is an odd thing to want to do to actually cause an "auto click". Rather, since that would just emit the signal to cause any attached slot(s) to run, simply call the desired slot method(s) yourself explicitly in code.

          Ramkumar MohanR Offline
          Ramkumar MohanR Offline
          Ramkumar Mohan
          wrote on last edited by
          #4

          @JonB

          I wrote this code,

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QCryptographicHash>
          #include <QDebug>
          #include "qaeswrap.h"
          #include <memory.h>
          #include "aes.h"
          #include <QThread>
          
          
          MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
             ui->setupUi(this);
             on_pushButton_clicked();
          }
          
          MainWindow::~MainWindow()
          {
             delete ui;
          }
          
          void MainWindow::on_pushButton_clicked()
          {
               qDebug()<<"Enter";
          }
          

          I have called the pushbutton ui->setupUi(this) below. What I need is button call after Mainwindow is run. In this code Mainwindow is displayed after button call.

          JonBJ T 2 Replies Last reply
          0
          • Ramkumar MohanR Ramkumar Mohan

            @JonB

            I wrote this code,

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QCryptographicHash>
            #include <QDebug>
            #include "qaeswrap.h"
            #include <memory.h>
            #include "aes.h"
            #include <QThread>
            
            
            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
               ui->setupUi(this);
               on_pushButton_clicked();
            }
            
            MainWindow::~MainWindow()
            {
               delete ui;
            }
            
            void MainWindow::on_pushButton_clicked()
            {
                 qDebug()<<"Enter";
            }
            

            I have called the pushbutton ui->setupUi(this) below. What I need is button call after Mainwindow is run. In this code Mainwindow is displayed after button call.

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

            @Ramkumar-Mohan said in How to auto click pushButton in ui after running the mainwindow ?:

            after Mainwindow is run

            I suspect you mean after it is shown? Override its QWidget::showEvent(QShowEvent *event) and call on_pushButton_clicked() from there.

            Another alternative is to use QTimer::singleShot() and call it from within a slot attached to that, so after a delay.

            1 Reply Last reply
            2
            • Ramkumar MohanR Ramkumar Mohan

              @JonB

              I wrote this code,

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include <QCryptographicHash>
              #include <QDebug>
              #include "qaeswrap.h"
              #include <memory.h>
              #include "aes.h"
              #include <QThread>
              
              
              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
                 ui->setupUi(this);
                 on_pushButton_clicked();
              }
              
              MainWindow::~MainWindow()
              {
                 delete ui;
              }
              
              void MainWindow::on_pushButton_clicked()
              {
                   qDebug()<<"Enter";
              }
              

              I have called the pushbutton ui->setupUi(this) below. What I need is button call after Mainwindow is run. In this code Mainwindow is displayed after button call.

              T Offline
              T Offline
              tapsbrighton
              wrote on last edited by
              #6

              @Ramkumar-Mohan You could make the on_pushButton_clicked() a public slot and then call it from your main.cpp like:

              MainWindow w;
              w.show();
              w.on_pushButton_clicked();
              
              SGaistS 1 Reply Last reply
              0
              • T tapsbrighton

                @Ramkumar-Mohan You could make the on_pushButton_clicked() a public slot and then call it from your main.cpp like:

                MainWindow w;
                w.show();
                w.on_pushButton_clicked();
                
                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @tapsbrighton that will the same effect as calling the method in the constructor. The widget is not show once it's constructed but once show has been called and the event loop is running.
                The suggestion of @JonB is better. If visual presence is required then using the showEvent method is the way to go.

                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
                0

                • Login

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