Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] emit error(ErrorString) -> cannot be used as a function!

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rentner323
    wrote on 25 Nov 2013, 10:03 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Nov 2013, 11:08 last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 25 Nov 2013, 11:10 last edited by
        #3

        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.

        (Z(:^

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rentner323
          wrote on 25 Nov 2013, 11:33 last edited by
          #4

          [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!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 25 Nov 2013, 22:18 last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            1/5

            25 Nov 2013, 10:03

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved