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. Troubles with QPushButton::clicked
Forum Updated to NodeBB v4.3 + New Features

Troubles with QPushButton::clicked

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 887 Views 1 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.
  • G Offline
    G Offline
    gav007
    wrote on last edited by
    #1

    Hi,

    In Qt Designer, I created on the same way 2 flat QPushButtons in a widget (FYI a "duplicate" and a "remove" button).
    0_1539329513396_qtbuttons.png
    Both have similar caracteristics (here are the ones for the right "remove" button):
    0_1539329780754_qtbuttons2.png
    From the menu "Go to slots ...", I created a clicked() slot method for every one

    private slots:
        ...
        void on_duplicateButton_clicked();
        void on_removeButton_clicked();
    

    At runtime, clicking on the left button ("duplicate" button) is working fine. But clicking on the right button ("remove" button) does not call the slot method. Graphically, one can see that the button is correctly clicked (and is then on front of the UI).
    Any attempt to replace the "clicked" slot with another one (pressed or released) did not succeed.

    What have I done wrong ? Any help is welcome.

    To be noted : according to the selection in a tree widget, those buttons are set visible or not. Could this be the reason of any problem ?

    Best regards.

    Environment:
    Qt Creator 4.7.1 on Windows 10
    Qt 5.11.2 (MSVC 2015, 32bit)

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

      Hi
      the remove button MUST be called "removeButton" exactly for it to work so that's first check.

      Its very convenient with the auto clot creation and connection but sadly it also breaks very easy.
      So i must recommend for real applications, to use
      manual connect statements using the new syntax
      https://wiki.qt.io/New_Signal_Slot_Syntax

      This will give an error on compile time if not working.

      1 Reply Last reply
      1
      • G Offline
        G Offline
        gav007
        wrote on last edited by
        #3

        @mrjj
        Many thanks for those info.
        I created the manual connection in the main window

        connect( ui->removeButton, &QPushButton::clicked, this, &MainWindow::on_removeButton_clicked );
        

        and it works :-) .

        Does it mean that it is not recommended to use the Signals/Slots editor from Qt Designer ?
        In the caracteristics panel of Qt Designer, the button is well called "removeButton". Hence in this case, is this really the reason ?

        Many thanks again.

        Best regards

        mrjjM 1 Reply Last reply
        0
        • G gav007

          @mrjj
          Many thanks for those info.
          I created the manual connection in the main window

          connect( ui->removeButton, &QPushButton::clicked, this, &MainWindow::on_removeButton_clicked );
          

          and it works :-) .

          Does it mean that it is not recommended to use the Signals/Slots editor from Qt Designer ?
          In the caracteristics panel of Qt Designer, the button is well called "removeButton". Hence in this case, is this really the reason ?

          Many thanks again.

          Best regards

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @gav007
          well, the Signal and slot editor work via a naming convention
          so if either the slot or widget is renamed, it's not connected anymore. ( silently)
          So it breaks very easy even if very nice to use.

          So for a one-man project, it might not be that bad to use but for
          bigger projects it's not optimal.

          So yes, for the compile-time errors and not silent fail at runtime, it's very recommended
          to use.

          Im not sure if the name was the case for not working.

          anyway, it simply works from Qt calling
          QMetaObject::connectSlotsByName();

          which looks for on_WidgetName_Signal
          so if it find a match it connects for you.

          1 Reply Last reply
          2
          • G Offline
            G Offline
            gav007
            wrote on last edited by
            #5

            OK. Thanks for the advice. It's added in my coding rules ;-)
            The manual connection solved my issue.

            Best regards.

            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