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. Connect a SIGNAL to a SIGNAL with more arguments
Forum Updated to NodeBB v4.3 + New Features

Connect a SIGNAL to a SIGNAL with more arguments

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 414 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.
  • L Offline
    L Offline
    leonardo M B
    wrote on last edited by
    #1

    I have a SIGNAL that takes data as arguments and I would Like to connect to another SIGNAL that receives the same data, but also takes a boolean argument. This boolean argument I want to be the state of a checkbox. My idea was something like this:

    connect(_periodSelector, SIGNAL(newDateTimes(QDateTime, QDateTime)), this, SIGNAL(changeAbsolutePeriods(QDateTime,QDateTime, bool =_checkbox->isChecked)));
    

    How Can I do This?

    J.HilkJ 1 Reply Last reply
    0
    • E Offline
      E Offline
      Emre MUTLU
      wrote on last edited by Emre MUTLU
      #3
      connect(_periodSelector,&_periodSelectorClass::newDateTimes,[this](QDateTime dateTime){
      emit this->changeAbsolutePeriods(dateTime,_checkbox->isChecked());
      };
      

      i'm not sure but maybe something like this will work

      1 Reply Last reply
      2
      • L leonardo M B

        I have a SIGNAL that takes data as arguments and I would Like to connect to another SIGNAL that receives the same data, but also takes a boolean argument. This boolean argument I want to be the state of a checkbox. My idea was something like this:

        connect(_periodSelector, SIGNAL(newDateTimes(QDateTime, QDateTime)), this, SIGNAL(changeAbsolutePeriods(QDateTime,QDateTime, bool =_checkbox->isChecked)));
        

        How Can I do This?

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

        @leonardo-M-B by using the "new" connect syntax and a lambda as forth argument

        or by going the along way and creating a slot in your class wherein you emit the new signal with the additional parameter


        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
        3
        • E Offline
          E Offline
          Emre MUTLU
          wrote on last edited by Emre MUTLU
          #3
          connect(_periodSelector,&_periodSelectorClass::newDateTimes,[this](QDateTime dateTime){
          emit this->changeAbsolutePeriods(dateTime,_checkbox->isChecked());
          };
          

          i'm not sure but maybe something like this will work

          1 Reply Last reply
          2
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #4

            In order to avoid some weird crashes, you should use a context object in your connect statement:

            connect(_periodSelector,&_periodSelectorClass::newDateTimes,this,[this](QDateTime dateTime){
            emit this->changeAbsolutePeriods(dateTime,_checkbox->isChecked());
            };
            

            (notice the extra this as third argument)

            Otherwise, if the object pointed to by this is destroyed, the connection will not disconnect automatically. Once the lambda is then executed it will have a dangling this pointer. With these kinds of lambdas (that just wrap another function call) it is usually quite easy to find the right context object.

            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