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. Noob anomaly - ghost signal emission
Forum Updated to NodeBB v4.3 + New Features

Noob anomaly - ghost signal emission

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 520 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.
  • P Offline
    P Offline
    Pepas
    wrote on last edited by
    #1

    Hi

    Well I'm aware that I haven't spent much time in qt and its docs, but the latest magic 'anomaly' I've faced pushed me into corner:P

    1. I have QWidget in mainwindow.ui, promoted to my custom FileCommander class which implements QTreeview and QFileSystemModel.
    2. Still, above things are part of my mainwindow, a widget with treeview, but a bit separated for better management.
    3. Once I decided to make an event 'clicked' on QTreeView
    4. Then I thought to myself, damn, I need to get that event in my mainwindow, so I moved generated FileCommander_clicked() to MainWindow in order to connect and I removed slot from FileCommander at all:P
    5. My mind blowed up when I saw it working without additional connect (I used to write delegates/etc in the past).

    Well as far as I know signals are emited in such fashion, the problem is that I can't sort out that sick behavior:P By adding just a proper slot that matched myClass_clicked in other class I did catch the signal. I feel like it could drive me into trouble in future and I consider changing it's name and connect manually to know what's going on:P

    Could someone tell me where/when it happens that this slot receives emission in mainwindow without any explicit declaration? (it feels like an event going from the bottom to top in some standard messaging system... anyway)
    Second thing, do you advise to change its name and connect manually to keep things more readable though the name seems to be self explainatory ? :P

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

      You've experienced the horror/ beauty of connectSlotsByName method. It is invoked in ui_*.h header which is generated by UIC when you compile your project.

      (Z(:^

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

        Hi
        In setupUI (), the generated code calls
        QMetaObject::connectSlotsByName
        http://doc.qt.io/qt-5/qmetaobject.html#connectSlotsByName
        So if name matches the "auto" syntax then its made.

        I can only recommend NOT using auto connect feature and use the new
        syntax to manually hook up widgets to slots because using auto,

        • If you rename widgets, it will break and
          also renaming slot breaks code
          so the auto connect feature is best left for prototyping etc.

        Using the new syntax, you would discover at first compile that you broke the click of a button.
        otherwise, its a silent fail which never is really desirable for a real application.

        https://wiki.qt.io/New_Signal_Slot_Syntax

        1 Reply Last reply
        5
        • P Offline
          P Offline
          Pepas
          wrote on last edited by Pepas
          #4

          Straight to the point. Thank you guys!

          J.HilkJ 1 Reply Last reply
          0
          • P Pepas

            Straight to the point. Thank you guys!

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Pepas an easy way to prevent accidental connectSlotsByName connects would be the use of proper CamelCase notation like every self-respecting c++ programmer should :P


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            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