Important: Please read the Qt Code of Conduct -

[solved] emit error(ErrorString) -> cannot be used as a function!

  • Hi,
    In my Object I declared a Signal:
    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: ";
    emit error(errorString);


  • Lifetime Qt Champion


    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

  • Moderators

    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.

  • [quote author="SGaist" date="1385377701"]
    Are you sure you are not already using error as a variable in the same function ?

    That was the Problem! I've totally overlooked that.


  • Lifetime Qt Champion

    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 :)

Log in to reply