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. Clicked signal not emitted
Forum Updated to NodeBB v4.3 + New Features

Clicked signal not emitted

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 1.0k 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.
  • dualD Offline
    dualD Offline
    dual
    wrote on last edited by
    #1

    Hello guys,
    I have a problem: i connected the clicked signal to a slot function but it is never emitted even if the PushButton looks as pressed and release graphically.
    Using emit button->clicked() the signal is fired, so I think that the connect works well.

    I paste here some code:

    void Ui_MainWindow::setupUi(QMainWindow *MainWindow)
    {
        if (MainWindow->objectName().isEmpty())
            MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
        MainWindow->resize(800, 600);
        actionNew_File = new QAction(MainWindow);
        actionNew_File->setObjectName(QString::fromUtf8("actionNew_File"));
        actionOpen_File = new QAction(MainWindow);
        actionOpen_File->setObjectName(QString::fromUtf8("actionOpen_File"));
        actionLogout = new QAction(MainWindow);
        actionLogout->setObjectName(QString::fromUtf8("actionLogout"));
        actionTintero_0_1 = new QAction(MainWindow);
        actionTintero_0_1->setObjectName(QString::fromUtf8("actionTintero_0_1"));
        centralwidget = new QWidget(MainWindow);
        centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
        verticalLayoutWidget = new QWidget(centralwidget);
        verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
        verticalLayoutWidget->setGeometry(QRect(10, 30, 191, 501));
        verticalLayout = new QVBoxLayout(verticalLayoutWidget);
        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
        verticalLayout->setContentsMargins(0, 0, 0, 0);
    
    
        avatarLabel = new ClickableLabel(verticalLayoutWidget);
        avatarLabel->setObjectName(QString::fromUtf8("avatarLabel"));
        avatarLabel->setAlignment(Qt::AlignCenter);
    
        verticalLayout->addWidget(avatarLabel);
    
        usernameLabel = new QLabel(verticalLayoutWidget);
        usernameLabel->setObjectName(QString::fromUtf8("usernameLabel"));
        usernameLabel->setAlignment(Qt::AlignCenter);
    
        verticalLayout->addWidget(usernameLabel);
    
        recentDocsLabel = new QListView(verticalLayoutWidget);
        recentDocsLabel->setObjectName(QString::fromUtf8("recentDocsLabel"));
    
        verticalLayout->addWidget(recentDocsLabel);
    
    
        scrollArea = new QScrollArea(centralwidget);
        scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
        scrollArea->setGeometry(QRect(210, 30, 581, 501));
        scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
        scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded);
        scrollArea->setWidgetResizable(true);
        scrollAreaWidgetContents = new QWidget();
        scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
        scrollAreaWidgetContents->setGeometry(QRect(0, 0, 579, 499));
        docTableWdg = new QGridLayout(scrollAreaWidgetContents);
        docTableWdg->setObjectName(QString::fromUtf8("docTableWdg"));
        docTableWdg->setGeometry(QRect(10, 10, 561, 481));
        scrollArea->setWidget(scrollAreaWidgetContents);
    
    [...]
    
    } // setupUi
    
    [...] 
    QLabel *newDoc = new QLabel();
    
    auto createDocButton = new QPushButton();
        createDocButton->setEnabled(true);
        createDocButton->setText("new document");
    
      QFrame *container = new QFrame();
        container->setLayout(new QVBoxLayout);
        container->layout()->addWidget(newDoc);
        container->layout()->addWidget(createDocButton);
    
    
    
        this->docTableWdg->addWidget(container, 0, 0);
    
    bool success = connect(createDocButton, &QAbstractButton::clicked, this, &Ui_MainWindow::createDocument);
    qDebug()<<success; //this prints true
    [...]
    void Ui_MainWindow::createDocument(){
        qDebug()<<"i'm here";
    }
    
    

    Thanks in advance for helping

    J 1 Reply Last reply
    0
    • dualD dual

      Hello guys,
      I have a problem: i connected the clicked signal to a slot function but it is never emitted even if the PushButton looks as pressed and release graphically.
      Using emit button->clicked() the signal is fired, so I think that the connect works well.

      I paste here some code:

      void Ui_MainWindow::setupUi(QMainWindow *MainWindow)
      {
          if (MainWindow->objectName().isEmpty())
              MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
          MainWindow->resize(800, 600);
          actionNew_File = new QAction(MainWindow);
          actionNew_File->setObjectName(QString::fromUtf8("actionNew_File"));
          actionOpen_File = new QAction(MainWindow);
          actionOpen_File->setObjectName(QString::fromUtf8("actionOpen_File"));
          actionLogout = new QAction(MainWindow);
          actionLogout->setObjectName(QString::fromUtf8("actionLogout"));
          actionTintero_0_1 = new QAction(MainWindow);
          actionTintero_0_1->setObjectName(QString::fromUtf8("actionTintero_0_1"));
          centralwidget = new QWidget(MainWindow);
          centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
          verticalLayoutWidget = new QWidget(centralwidget);
          verticalLayoutWidget->setObjectName(QString::fromUtf8("verticalLayoutWidget"));
          verticalLayoutWidget->setGeometry(QRect(10, 30, 191, 501));
          verticalLayout = new QVBoxLayout(verticalLayoutWidget);
          verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
          verticalLayout->setContentsMargins(0, 0, 0, 0);
      
      
          avatarLabel = new ClickableLabel(verticalLayoutWidget);
          avatarLabel->setObjectName(QString::fromUtf8("avatarLabel"));
          avatarLabel->setAlignment(Qt::AlignCenter);
      
          verticalLayout->addWidget(avatarLabel);
      
          usernameLabel = new QLabel(verticalLayoutWidget);
          usernameLabel->setObjectName(QString::fromUtf8("usernameLabel"));
          usernameLabel->setAlignment(Qt::AlignCenter);
      
          verticalLayout->addWidget(usernameLabel);
      
          recentDocsLabel = new QListView(verticalLayoutWidget);
          recentDocsLabel->setObjectName(QString::fromUtf8("recentDocsLabel"));
      
          verticalLayout->addWidget(recentDocsLabel);
      
      
          scrollArea = new QScrollArea(centralwidget);
          scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
          scrollArea->setGeometry(QRect(210, 30, 581, 501));
          scrollArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
          scrollArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded);
          scrollArea->setWidgetResizable(true);
          scrollAreaWidgetContents = new QWidget();
          scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
          scrollAreaWidgetContents->setGeometry(QRect(0, 0, 579, 499));
          docTableWdg = new QGridLayout(scrollAreaWidgetContents);
          docTableWdg->setObjectName(QString::fromUtf8("docTableWdg"));
          docTableWdg->setGeometry(QRect(10, 10, 561, 481));
          scrollArea->setWidget(scrollAreaWidgetContents);
      
      [...]
      
      } // setupUi
      
      [...] 
      QLabel *newDoc = new QLabel();
      
      auto createDocButton = new QPushButton();
          createDocButton->setEnabled(true);
          createDocButton->setText("new document");
      
        QFrame *container = new QFrame();
          container->setLayout(new QVBoxLayout);
          container->layout()->addWidget(newDoc);
          container->layout()->addWidget(createDocButton);
      
      
      
          this->docTableWdg->addWidget(container, 0, 0);
      
      bool success = connect(createDocButton, &QAbstractButton::clicked, this, &Ui_MainWindow::createDocument);
      qDebug()<<success; //this prints true
      [...]
      void Ui_MainWindow::createDocument(){
          qDebug()<<"i'm here";
      }
      
      

      Thanks in advance for helping

      J Offline
      J Offline
      jay1
      wrote on last edited by
      #2

      @dual said in Clicked signal not emitted:

      createDocument

      Is the

      createDocument()
      

      function created as a slot ?

      dualD 1 Reply Last reply
      0
      • J jay1

        @dual said in Clicked signal not emitted:

        createDocument

        Is the

        createDocument()
        

        function created as a slot ?

        dualD Offline
        dualD Offline
        dual
        wrote on last edited by
        #3

        @jay1 yup, it is

        [...]
        private slots:
            void createDocument();
        [...]
        
        mrjjM 1 Reply Last reply
        0
        • dualD dual

          @jay1 yup, it is

          [...]
          private slots:
              void createDocument();
          [...]
          
          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @dual
          Hi
          The name seems a bit odd Ui_MainWindow.
          You are not editing the auto-generated file ?

          class Ui_MainWindow
          {
          public:
              QWidget *centralwidget;
          .....
              void setupUi(QMainWindow *MainWindow)
              {
          

          This one ?
          it has this warning in top
          alt text
          maybe you must expand it.

          I would assume

          void Ui_MainWindow::createDocument(){
          qDebug()<<"i'm here";
          }

          should be

          void MainWindow::createDocument(){
          qDebug()<<"i'm here";
          }

          dualD 1 Reply Last reply
          3
          • mrjjM mrjj

            @dual
            Hi
            The name seems a bit odd Ui_MainWindow.
            You are not editing the auto-generated file ?

            class Ui_MainWindow
            {
            public:
                QWidget *centralwidget;
            .....
                void setupUi(QMainWindow *MainWindow)
                {
            

            This one ?
            it has this warning in top
            alt text
            maybe you must expand it.

            I would assume

            void Ui_MainWindow::createDocument(){
            qDebug()<<"i'm here";
            }

            should be

            void MainWindow::createDocument(){
            qDebug()<<"i'm here";
            }

            dualD Offline
            dualD Offline
            dual
            wrote on last edited by
            #5

            @mrjj yes I'm using the auto-generated file but I deleted from my project the .ui file in order to avoid the problem in the top comment.
            I paste here the class declaration:

            class Ui_MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            
            private:
            [...]
                QWidget *centralwidget;
                QWidget *verticalLayoutWidget;
                QVBoxLayout *verticalLayout;
            [...]
            

            Btw emitting the "clicked" signal in code, the slot triggers.

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

              Hi,

              Do not edit the auto-generated file. It even has a warning on top saying so.

              You have to edit the other on that makes use of that generated class.

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

              dualD 1 Reply Last reply
              1
              • SGaistS SGaist

                Hi,

                Do not edit the auto-generated file. It even has a warning on top saying so.

                You have to edit the other on that makes use of that generated class.

                dualD Offline
                dualD Offline
                dual
                wrote on last edited by
                #7

                @SGaist hi, thanks for the reply.
                Can you explain better this concept? I've previously modified the auto-generated file with other stuff, but the only thing that doesn't work is the pushButton, the remaining stuff works well.

                Sorry for these silly questions, but I am a newbie in qt.

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

                  The most simple is to take a look at the Qt Designer Calculator Form Example.

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

                  dualD 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    The most simple is to take a look at the Qt Designer Calculator Form Example.

                    dualD Offline
                    dualD Offline
                    dual
                    wrote on last edited by
                    #9

                    @SGaist thank you again. So my last question is: how can I modify the gui obtained with the auto-generated file in a "legal" way? Is it possible in code or should I draw the .ui file and auto-generate the .h file again? And again, let's suppose I have to modify an auto-gen .h file in some way after some time, how can I do?

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

                      What modifications do you have in mind ?
                      Again, this is a generated file so do not even store in your version control system. It's created based on the .ui file and will be regenerated when that file is modified.

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

                      dualD 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        What modifications do you have in mind ?
                        Again, this is a generated file so do not even store in your version control system. It's created based on the .ui file and will be regenerated when that file is modified.

                        dualD Offline
                        dualD Offline
                        dual
                        wrote on last edited by
                        #11

                        @SGaist I need to change the displayed object dynamically: I have a scroll area, a grid layout and some labels in it, but the number of labels is not fixed and may change over time. How can I manage this problem?

                        jsulmJ 1 Reply Last reply
                        0
                        • dualD dual

                          @SGaist I need to change the displayed object dynamically: I have a scroll area, a grid layout and some labels in it, but the number of labels is not fixed and may change over time. How can I manage this problem?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @dual In your main window (MainWindow class or whatever name you gave it not Ui_MainWindow) you can access your UI widgets/layouts via ui->WIDGET_NAME.

                          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