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. Slot with default argument

Slot with default argument

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 10.6k Views
  • 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    Hi,
    i thought that i could connect a signal to a slot with a default argument. Like said in the doc

    My signal:

    void newData();
    

    My slot:

    void updateValue(bool all = false);
    

    Connect:

    QObject::connect(class1, &MyClass1::newData, class2, &MyClass2::updateValue);
    

    When i want to connect them i get
    C2338: The slot requires more arguments than the signal provides.

    1 Reply Last reply
    0
    • BjornWB Offline
      BjornWB Offline
      BjornW
      wrote on last edited by
      #2

      Try

      QObject::connect(class1, &MyClass1::newData, [=](){ class2->updateValue();});
      
      beeckscheB 1 Reply Last reply
      1
      • BjornWB BjornW

        Try

        QObject::connect(class1, &MyClass1::newData, [=](){ class2->updateValue();});
        
        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @BjornW
        Yes, connect to lambda function works perfectly.

        But i thought that connect to a slot with default argument was previos possible. Or am i wrong with that?

        K 1 Reply Last reply
        0
        • BjornWB Offline
          BjornWB Offline
          BjornW
          wrote on last edited by
          #4

          I do not know :-)

          1 Reply Last reply
          0
          • beeckscheB beecksche

            @BjornW
            Yes, connect to lambda function works perfectly.

            But i thought that connect to a slot with default argument was previos possible. Or am i wrong with that?

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            @beecksche

            There are two methods possible for connect

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            3
            • m.sueM Offline
              m.sueM Offline
              m.sue
              wrote on last edited by m.sue
              #6

              Hi,
              It was possible and I would think it's still possible with the SIGNAL, SLOT Macros.
              -Michael.

              beeckscheB 1 Reply Last reply
              2
              • m.sueM m.sue

                Hi,
                It was possible and I would think it's still possible with the SIGNAL, SLOT Macros.
                -Michael.

                beeckscheB Offline
                beeckscheB Offline
                beecksche
                wrote on last edited by
                #7

                @koahnig
                @m.sue
                You're right! Thanks!

                Here is the answer! I need to use the string based syntax !

                1 Reply Last reply
                0
                • BjornWB Offline
                  BjornWB Offline
                  BjornW
                  wrote on last edited by
                  #8

                  I would strongly recommend the Qt5 way though (using lambdas)!

                  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