can i write a slots with defalut param?



  • 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?



  • Hi,

    In your header file

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


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



  • 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);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.