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. Can we have signal with default arguments and pass it to solt
Forum Updated to NodeBB v4.3 + New Features

Can we have signal with default arguments and pass it to solt

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 5.9k Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    for exampple

    class A {
    signals
    signal1( int A,int B,bool val = false);

    }

    class B {

    public slot
    slot1 (int A, int B, bool val = false)

    }

    A a
    B b

    connect (a,signal1,b,slot1)

    K 1 Reply Last reply
    0
    • Q Qt Enthusiast

      for exampple

      class A {
      signals
      signal1( int A,int B,bool val = false);

      }

      class B {

      public slot
      slot1 (int A, int B, bool val = false)

      }

      A a
      B b

      connect (a,signal1,b,slot1)

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

      @Qt-Enthusiast

      Did you see this ?

      But you need to use the string-based version of connect.

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

      1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        connect doesn't care about parameter values, so as long as the number of params matches or slot has less of them you can do the connection. You don't need to use the string based syntax for your example:

        connect(&a, &A::signal1, &b, &B::slot1);
        
        //you can do any of these:
        emit signal1(42,43);
        emit signal1(42,43, true);
        slot1(42,43);
        slot1(42,43, true);
        

        The only case where you need the string based version is when the signal has less parameters than the slot and the extra slot arguments have default values, which is not the case here.

        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