Results 1 to 5 of 5

Thread: Default value for a QStringlist

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2011
    Location
    Living in Spain 100km North of Valencia
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: Default value for a QStringlist

    Thank you Santosh

    I have not explained myself well. I want a DEFAULT value for a variable in a an arguments list. An example follows:

    Qt Code:
    1. #ifndef MYINPUTDLG_H
    2. #define MYINPUTDLG_H
    3.  
    4. #include "myinputdlg_global.h"
    5. #include <utilities.h>
    6. #include <Dialog.h>
    7.  
    8. class MYINPUTDLGSHARED_EXPORT MyinputDlg
    9. {
    10.  
    11. public:
    12. MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = "", QString def = "");
    13.  
    14. errorNumbers error;
    15. QVariant retVal;
    16. private:
    17. QString m_title, m_lblText, m_def;
    18. };
    19.  
    20. #endif // MYINPUTDLG_H
    To copy to clipboard, switch view to plain text mode 

    Obviously this does not compile because the lblTexts is a list NOT a QString. lblTexts = {} does nor work either.
    Is there a way of declaring a default for a QStringList in a case like this?
    Thank you again for you help.
    Regards
    G

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: Default value for a QStringlist

    Qt Code:
    1. MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = "");
    To copy to clipboard, switch view to plain text mode 
    and You have an empty list as the default value.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Default value for a QStringlist

    Is there a way of declaring a default for a QStringList in a case like this?
    QStringList and QString variables are always defaulted to an empty QStringList (same as assigning it to QStringList(), as Lesiok explains), and QString defaults to an empty string. So these two are exactly the same in their effect:

    Qt Code:
    1. MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = "");
    2.  
    3. // and
    4.  
    5. MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts, QString def);
    To copy to clipboard, switch view to plain text mode 

    The only time you need the first form is if the variable(s) with the default value(s) are not at the end of the list of variables:

    Qt Code:
    1. MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = "Something non-default");
    To copy to clipboard, switch view to plain text mode 
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. The following user says thank you to d_stranz for this useful post:

    GrahamB (13th May 2017)

Similar Threads

  1. Help QStringList
    By pcoliver in forum Qt Programming
    Replies: 0
    Last Post: 15th September 2011, 10:15
  2. Plz help me,I met a bug about QStringList
    By study_c in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2010, 15:56
  3. QStringList
    By jaca in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2008, 10:12
  4. QStringList
    By dragon in forum Newbie
    Replies: 2
    Last Post: 8th June 2007, 17:26
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.