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. "New" signal slot syntax with signals defined in abstract base class requires horrible cast?
Forum Updated to NodeBB v4.3 + New Features

"New" signal slot syntax with signals defined in abstract base class requires horrible cast?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 321 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.
  • DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by Diracsbracket
    #1

    Hi.
    I thought I'd eliminate the SIGNAL/SLOT macros from my code until I found out that I needed to do horrible casts like this:

    connect(app_->data_manager(), static_cast<void (DataManager::*)(const Data&)>(&DataManager::CurrentDataChanged), &DataBase::CurrentDataChanged);
    

    because the signal CurrentDataChanged is defined in the abstract base class of DataManager.

    Is this really the correct way to do this with the new syntax? Once I realized this, I just quickly reverted to the SIGNAL/SLOT macros, because the new syntax just seems too much of a hassle.

    JonBJ JKSHJ 2 Replies Last reply
    0
    • DiracsbracketD Diracsbracket

      Hi.
      I thought I'd eliminate the SIGNAL/SLOT macros from my code until I found out that I needed to do horrible casts like this:

      connect(app_->data_manager(), static_cast<void (DataManager::*)(const Data&)>(&DataManager::CurrentDataChanged), &DataBase::CurrentDataChanged);
      

      because the signal CurrentDataChanged is defined in the abstract base class of DataManager.

      Is this really the correct way to do this with the new syntax? Once I realized this, I just quickly reverted to the SIGNAL/SLOT macros, because the new syntax just seems too much of a hassle.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Diracsbracket
      Well, that depends on exactly how you have defined the signatures of the signal and the slot. Qt has plenty of signals/slots defined in its abstract base classes without requiring the casting you show.

      It's up to you, but personally at least I still miles prefer new style with edit- and compile-time help, as opposed to the old macros which if you get wrong you only find out at runtime. You can always typedef the signatures out of the classes to use elsewhere, so that even if that code is needed you don't have to write it every time.

      1 Reply Last reply
      4
      • DiracsbracketD Diracsbracket

        Hi.
        I thought I'd eliminate the SIGNAL/SLOT macros from my code until I found out that I needed to do horrible casts like this:

        connect(app_->data_manager(), static_cast<void (DataManager::*)(const Data&)>(&DataManager::CurrentDataChanged), &DataBase::CurrentDataChanged);
        

        because the signal CurrentDataChanged is defined in the abstract base class of DataManager.

        Is this really the correct way to do this with the new syntax? Once I realized this, I just quickly reverted to the SIGNAL/SLOT macros, because the new syntax just seems too much of a hassle.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @Diracsbracket said in "New" signal slot syntax with signals defined in abstract base class requires horrible cast?:

        because the signal CurrentDataChanged is defined in the abstract base class of DataManager.

        That doesn't sound like a reason for casting.

        • What error message do you get without the cast?
        • Is CurrentDataChanged overloaded or overridden?

        As @JonB mentioned, the signals of QAbstractItemView (https://doc.qt.io/qt-5/qabstractitemview.html#signals ) don't require casting, for example.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        4

        • Login

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