Results 1 to 3 of 3

Thread: [SOLVED] connect overloaded signal with parameter

  1. #1
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default [SOLVED] connect overloaded signal with parameter

    Hi

    I prefer to use the more modern signal/slot connect() version as it is typesafe at run-time. Copied from the Qt documentation: "QObject::connect(lineEdit, &QLineEdit::textChanged, label, &QLabel::setText);". How is this done when there are overloaded functions and/or signals?

    Examples:
    • "connect(camera, &QCamera::error, this, &CaptureDialog::errorSlot);" does not compile because there are two QCamera::error functions: the signal "QCamera::error(QCamera::Error)" and the regular function "QCamera::error() const"
    • "connect(camera, &QCamera::lockStatusChanged, this, &CaptureDialog::lockStatusChangedSlot);" does not compile because there are two signals QCamera::lockStatusChanged with different parameters
    Last edited by Al_; 2nd May 2014 at 11:27.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: connect overloaded signal with parameter

    Quote Originally Posted by Al_ View Post
    I prefer to use the more modern signal/slot connect() version as it is typesafe at run-time.
    Even the old connects are typesafe at runtime. What you probably meant is typesafe/typechecked at compile time.

    Quote Originally Posted by Al_ View Post
    Examples:
    • "connect(camera, &QCamera::error, this, &CaptureDialog::errorSlot);" does not compile because there are two QCamera::error functions: the signal "QCamera::error(QCamera::Error)" and the regular function "QCamera::error() const"
    • "connect(camera, &QCamera::lockStatusChanged, this, &CaptureDialog::lockStatusChangedSlot);" does not compile because there are two signals QCamera::lockStatusChanged with different parameters
    You need to provide disambiguation through casting

    Qt Code:
    1. connect(camera, static_cast<void(QCamera::*)(QCamera::Error)>(&QCamera::error), this, &CaptureDialog::errorSlot);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Al_ (2nd May 2014)

  4. #3
    Join Date
    Dec 2009
    Posts
    47
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: connect overloaded signal with parameter

    Great, thanks for quick reply. Works perfectly! I had played around with QMetaMethod, had tried to typedef; but casting did not come to my mind.

    PS: yes, I meant compile time.

Similar Threads

  1. Slot - Signal with parameter
    By Lodhart in forum Newbie
    Replies: 8
    Last Post: 10th April 2013, 11:08
  2. A Signal with Parameter from Qt C++ to QML
    By reinki0013 in forum Qt Quick
    Replies: 1
    Last Post: 8th November 2011, 14:12
  3. Replies: 3
    Last Post: 26th August 2011, 08:17
  4. Struggling with signal which has a default parameter.
    By JPNaude in forum Qt Programming
    Replies: 21
    Last Post: 21st January 2011, 09:40
  5. Problem with connect() (enum-type as parameter)
    By alu23 in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 08:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.