Results 1 to 4 of 4

Thread: Lambda callback functions

  1. #1
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Lambda callback functions

    In this article:

    http://byuu.org/articles/qt

    the author (who doesn't much like Qt) seems to claim that signals and slots could be replaced by lambdas, e.g.,

    Qt Code:
    1. saveButton.onClick = []() { file.saveToDisk(); };
    To copy to clipboard, switch view to plain text mode 

    I don't understand much about lambdas or C++11, but I am curious whether or not this is true, as the code presented in the article does look nice.

    FWIW I like signals and slots, and plan to continue using them... I'm just curious about this.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,688
    Thanks
    13
    Thanked 1,598 Times in 1,526 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Lambda callback functions

    He or she is entitled to their opinion. Seriously though, that's quite a rant. A cursory glance screams at me that the author was trying to make Qt do things the way he/she had always done them. This is a recipe for annoyance in any language. There's quite a collection of half truths and misunderstandings to boot.

    Sure, you can possibly do call backs using C++11 lambdas (or Standard library function wrappers, or Boost equivalents), but you certainly couldn't do that in 2005, or on every compiler, or on every platform. You can't do it cross-thread with queuing and argument marshalling where required.

    I think you would do yourself a favour by forming your own opinions.
    Last edited by ChrisW67; 12th March 2012 at 05:43.

  3. #3
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default Re: Lambda callback functions

    Yeah, I know it was rantish, and I didn't buy into it... I really like Qt. It was just that one line that caught my eye. I don't know if the lambda callbacks would actually be that easy or not.

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

    Default Re: Lambda callback functions

    It's likely Qt5 will support lambdas as slots when used with a C++11 compliant compiler.

    About the "article" itself, I always laugh at discussions like that where people assume everyone does things the way they do At times like this I'm willing to put such person in front of MSVC6 asking them to emulate what Qt's container classes do with MSVC6's implementation of STL and then to repeat that with a compiler that doesn't have an STL implementation at all.
    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. replacing signals and slots with callback functions
    By meena in forum Qt Programming
    Replies: 16
    Last Post: 23rd August 2010, 10:26
  2. callback to gui from thread...
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 20:52
  3. Regards CallBack Functions
    By Tavit in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2009, 17:16
  4. Non-Gui thread Callback API and Qt - how
    By The Storm in forum Qt Programming
    Replies: 9
    Last Post: 3rd November 2008, 20:24
  5. Callback in QT
    By gajendersingh in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 11:52

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.