0

Please see the space between QString and &. I am wondering in QT, is there any difference between QString& and QString &?

MrJre
  • 7,082
  • 7
  • 53
  • 66
dexterous
  • 6,422
  • 12
  • 51
  • 99
  • 2
    possible duplicate of [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – rubenvb Feb 19 '14 at 09:44

2 Answers2

3

No, there is no difference. It is pure C++ Syntax. C++ can be considered a white space independent language. Some discussion on that can be found here

Community
  • 1
  • 1
c_k
  • 1,746
  • 1
  • 20
  • 35
  • 2
    `&` in this context is not an operator, and regardless, precedence does not affect whether white space is relevant at all. –  Feb 19 '14 at 09:35
  • You are right. Didn't mean that to be a causality. I thought QString had the operator defined, which - you are right - is not the case. I'll update the answer. – c_k Feb 19 '14 at 09:40
  • 2
    Even if it _did_ have `operator&` defined, `QString&` would still be a reference to a QString. – MSalters Feb 19 '14 at 11:07
0

What c_k says is correct.

Note that with Qt's signals and slots, you can omit some of the syntax:

public slots:
    // Full syntax here
    void setName(const QString &name);

then:

// This is OK and Qt knows to connect the slot
connect(ui->nameEdit, SIGNAL(textEdited(QString)), this, SLOT(setName(QString)));

In fact the extra characters and spaces just make the connect call take a lot longer to execute.

Sez
  • 1,275
  • 11
  • 26