Solved I want check if one of my variables is null
-
Hi,
I want check if one of my variables is null
some code will execute .
This is my Code :if (ui->spinBox->text != &NULL ) { { ary[counter]=price; counter++; } ui->spinBox->clear(); } }
But i get this error:
error: lvalue required as unary '&' operand if (ui->spinBox->text != &NULL ) ^
Why?
Thanks.[Moved to C++ Gurus ~kshegunov]
-
&NULL
means nothing. You can't take the address of a constant, so the compiler is complaining about missing lvalue. Just use the implicit boolean interpretation:if (ui->spinBox->text) { // It is not null }
-
Hi,
Because null doesn't have any address. It's not a pointer.
QSpinBox::text
returns a QString. If you want to check if it's null then use QString::isNull. -
Thanks
i use this code:
QString s1 = "" ;
if ((ui->spinBox->text) != s1 )
and still get error
-
Because text is a function. Why not use
isNull
orisEmpty
? -
text is a method, not a member,
if ((ui->spinBox->text()) != s1 )
yet again, as said above, the correct way would beif (ui->spinBox->text().isEmpty())
-
Thanks for all
i solved my problem with this code :if (ui->spinBox->text().isEmpty())