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. what does 'Slots named on_foo_bar are error prone' mean?
Forum Updated to NodeBB v4.3 + New Features

what does 'Slots named on_foo_bar are error prone' mean?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 9.7k 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.
  • MozzieM Offline
    MozzieM Offline
    Mozzie
    wrote on last edited by
    #1

    Hi,

    When I use the "Go to slot" from qt creator design window to generate slots automaticly.
    I got warning "Slots named on_foo_bar are error prone"
    when there is only one this warning, everything seems to be fine.
    but after I got two warning, the second button can not trigger the slot.
    the name of first button is "toolButton" and the second button named "pushButton"
    when I change the "pushButton" to "pushButton_1" and re-generate slot, finaly the pushButton can trigger the slot.

    Thank you .

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      So the clazy warning has warned you about exactly the issue you encountered: when you use "Go to slot" Qt uses an automated connection mechanism called connectSlotsByName() where it uses some conventions to match objects, signals and slots. As clazy reports, and as you have experienced: this is convenient but error prone. It's very easy to make a mistake with this approach.

      To do this properly, use manual signal-slot connections with new connect syntax, like so:

      connect(toolButton, &QPushButton::clicked,
          this, &YourClassName::nameOfYourSlot);
      

      With this approach, your compiler will make sure that both objects, signal and slot are all correct.

      (Z(:^

      MozzieM 1 Reply Last reply
      7
      • sierdzioS sierdzio

        So the clazy warning has warned you about exactly the issue you encountered: when you use "Go to slot" Qt uses an automated connection mechanism called connectSlotsByName() where it uses some conventions to match objects, signals and slots. As clazy reports, and as you have experienced: this is convenient but error prone. It's very easy to make a mistake with this approach.

        To do this properly, use manual signal-slot connections with new connect syntax, like so:

        connect(toolButton, &QPushButton::clicked,
            this, &YourClassName::nameOfYourSlot);
        

        With this approach, your compiler will make sure that both objects, signal and slot are all correct.

        MozzieM Offline
        MozzieM Offline
        Mozzie
        wrote on last edited by
        #3

        @sierdzio
        Thank you very much

        1 Reply Last reply
        1
        • osirisgothraO Offline
          osirisgothraO Offline
          osirisgothra
          wrote on last edited by
          #4

          i think the real question should have been "If there is an option to do this in designer, and everyone is saying, don't use it, then why even have it?" Wouldn't it just be better to remove the feature--it gives a bad impression when a product has features that cause its own design rules to kick in, just seems like the user should be prompted instead.

          I'm truly glad you r/offmychess t finally, but please don't go too far, because you r/beyondvoxels and that implies that u r/donewithlife. Oh well time to git back to the lab, because azure sea here, I have a lot of work to do...

          sierdzioS 1 Reply Last reply
          1
          • osirisgothraO osirisgothra

            i think the real question should have been "If there is an option to do this in designer, and everyone is saying, don't use it, then why even have it?" Wouldn't it just be better to remove the feature--it gives a bad impression when a product has features that cause its own design rules to kick in, just seems like the user should be prompted instead.

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @osirisgothra because Qt is old and already has a ton of production code out there in the wild. Suddenly removing functionality is not so easy, needs to go through deprecation first and then removal much later, in a major release - so earliest in Qt 7.

            On the other hand - connectSlotsByName() is convenient and useful. Some people may prefer it, or use it only in limited cases like in small test example / test / POC apps, just to code them quicker. Also at some point I think QML used this feature internally. Maybe I'm wrong though.

            (Z(:^

            1 Reply Last reply
            2

            • Login

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