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



  • 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?


  • Lifetime Qt Champion

    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


  • 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 ?
    [/quote]

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

    Thanks!


  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.