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. An easier way to connect

An easier way to connect

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 956 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.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    I've been wondering, the new connection syntax tends to be a little over-verbose, can't we make use of the MOC to make connections really simple.

    After all, the connection boils down to connecting the signal of an instance to the slot of an instance. I.e.

    @connect(&obj1, &T1::someSig, obj1Ptr, T2::someSlot);@

    Occasionally, you have to deal with specifying overloads, making the syntax a horrid mess.

    Now, how cool would it be if you could simply:

    @connect(obj1.someSig, obj2Ptr->someSlot)@

    Naturally, this could not happen in C++, but the MOC can be used to generate the actual full connection syntax from this, with convenience features like:

    • automatically distinguish between references and pointers, using . for member access signifies the MOC needs to add the & operator before the object identifier

    • automatically handle necessary overloads, the user can use parameters to specify it, i.e. @obj.someSig(int)
      // vs
      obj.someSig(QString)@

    Instead of using connect() a macro can be used, such as:

    @Q_CONNECT(spinbox->valueChanged(int), slider->setValue)
    //
    // vs the current syntax, requiring explicit cast due to valueChanged() being overloaded
    //
    connect(spinbox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), slider, &QSlider::setValue);@

    Naturally, I don't put this in the context of a feature suggestion, the point is to get some feedback what people think before considering making it a feature suggestion.

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

      I think it is a good idea! Writing connect statements (both old and new syntax) is always a bit painful. Your solution would make it clean and simple.

      (Z(:^

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        I have created a "suggestion for the feature":https://bugreports.qt-project.org/browse/QTBUG-43087, vote for it to hopefully see it implemented sooner.

        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