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 i write a slots with defalut param?
Forum Update on Monday, May 27th 2025

can i write a slots with defalut param?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 656 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    i want to write a slot like this: void AddFile(const QStringList& list = QStringList());
    and then i can do this:

    1. connect(xxx, SIGNAL(add()), xxx, AddFile() );
    2. connect(xxx, SIGNAL(add(const QStringList&)), xxx, AddFile(const QStringList&));

    is it Right?

    ps. how to init a empty QStringList? what i wrote is right?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      In your header file

      void AddFile(const QStringList &l = QStringList());
      

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        thank you , and i tried it seems work fine.
        is it a good way to write like this?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Yes,

          is a C++ standard to define functions with default values for parameters.
          In example you can define

          // You MUST provide _a but can omit _b and _c
          void f(int _a, int _b = 0, int _c = 1);
          

          and you can call it

          f(3),
          f(1, 2);
          f(4, 5, 6);
          

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          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