Please see the space between QString and &. I am wondering in QT, is there any difference between QString& and QString &?
            Asked
            
        
        
            Active
            
        
            Viewed 776 times
        
    2 Answers
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
- 
                    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
- 
                    2Even 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
 
     
     
    