Results 1 to 3 of 3

Thread: QML function with optional parameters?

  1. #1
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    9

    Default QML function with optional parameters?

    I want to know if is possible to use optional parameters in a QML function.

    I tried:

    Qt Code:
    1. function danger(header, small, closeable = true) {
    2. setAlert(header, small, closeable)
    3. }
    To copy to clipboard, switch view to plain text mode 

    error: Syntax Error on closeable =

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QML function with optional parameters?

    I think JavaScript lacks the notion of a default value for function arguments, but you can probably do something like this

    Qt Code:
    1. setAlert(header, small, (typeof closeable !== 'undefined' ? closeable : true));
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    ricardodovalle (14th August 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QML function with optional parameters?

    Or a shorthand of:
    javascript Code:
    1. setAlert(header, small, closeable !== undefined ? closeable : true)
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 15th August 2014 at 10:14. Reason: updated contents
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Call JavaScript function with parameters from Qt C++
    By qt_developer in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2015, 00:31
  2. Replies: 4
    Last Post: 22nd January 2014, 01:25
  3. Replies: 4
    Last Post: 20th January 2011, 01:03
  4. QScript + get function call parameters
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2009, 15:30
  5. Wrong function according to parameters is taken
    By Lykurg in forum General Programming
    Replies: 5
    Last Post: 20th March 2009, 19:55

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.