[solved] emit error(ErrorString) -> cannot be used as a function!
-
wrote on 25 Nov 2013, 10:03 last edited by
Hi,
In my Object I declared a Signal:
@
signals:
void error(QString e);
@In serveral Functions i want to emit the error-Signal if Problems occur, this works:
@
emit error("Server Timeout!");
@This not (telling me: "'error' cannot be used as a function):
@
QString errorString;
errorString = "Error Occured: ";
errorString.append(pTcpSocket->errorString());
emit error(errorString);
@Why?
-
Hi,
Are you sure you are not already using error as a variable in the same function ?
Generally speaking using error as a function name is not a good idea, you should rather have something like :
@void errorOccured(const QString& errorText)@
It will make your code clearer to read and avoid name clashes.
Hope it helps
-
Hint You should be passing QStrings as const references:
@
voi error(const QString &e);
@Your second example should work just as the first one. Maybe you are using it outside of your class, or maybe it clashes with some other members (a variable, or a macro in one of the includes). Maybe try renaming it to something less common.
-
wrote on 25 Nov 2013, 11:33 last edited by
[quote author="SGaist" date="1385377701"]
Are you sure you are not already using error as a variable in the same function ?
[/quote]That was the Problem! I've totally overlooked that.
Thanks!
-
You're welcome !
Using meaningful names for functions and variables is a good way to avoid these kind of problems.
Since you have it working now, pleas update the thread title prepending [solved] so other forum users may know a solution has been found :)
1/5