Results 1 to 4 of 4

Thread: Why do we use "&"?

  1. #1
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Why do we use "&"?

    At the following web page: http://web.mit.edu/qt-dynamic/www/tu...torial-t2.html

    In:

    Qt Code:
    1. QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 

    Why is & used with quit and app? Cannot we use quit and app without &?

    Thanks.

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Why do we use "&"?

    connect expects a pointer.

  3. #3
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Why do we use "&"?

    "&" refers to the memory adress of the variable quit
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Why do we use "&"?

    "&" (in this context) means "take the address of what follows". In the example you quote, it's being used because "quit" and "app" are objects, and "connect" simply wants pointers to objects.

    In other cases the construct might be used on a call so that a paramater could be modified by the callee. Eg:
    Qt Code:
    1. int width;
    2. int height;
    3. height = getEiffelTowerDimensions(&width);
    4. ....
    5. int getEiffelTowerDimensions(int* width) {
    6. *width = 100;
    7. return 300;
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.