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. Trouble using 'override' keyword

Trouble using 'override' keyword

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 6.6k 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.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hello there,

    I am having trouble using the override keyword in one of my methods. Here is the code:
    @
    void NBhistoryInterface::addHistoryEntry(const QString & url) override
    {
    qDebug() << "SLOT: NBhistoryInterface::addHistoryEntry(const QString & url) override STATUS: Called";
    addHistoryItem("Title", url);
    qDebug() << "SLOT: NBhistoryInterface::addHistoryEntry(const QString & url) override STATUS: Completed";
    }
    @

    The program won't compile and gives this error:
    "expected function body after function declarator"

    What am I doing wrong? Thanks!

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Have you enabled C++11 support?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        I don't believe I have. How do I do that? I thought it was enabled be default...

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          It depends on your compiler. MSVC 2013 enables it by default.

          For GCC 4.8, you need to add this to your .pro file:

          @
          CONFIG += c++11
          @

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nicky j
            wrote on last edited by
            #5

            Im using whichever compiler comes in Qt Creator

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              There's no compiler coming with Qt Creator. The only "exception" if we can say, is the MinGW package which also provides the compiler.

              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
              • N Offline
                N Offline
                nicky j
                wrote on last edited by
                #7

                Sorry here is what I mean by the compiler that comes with Qt Creator: the one that runs when I press the green arrow button on the side. (I'm pretty sure thats compiling the code). Is that the MinGW package?

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  When you click the green Run button, Qt Creator simply runs whatever compiler you've installed and asked it to use.

                  To check the compiler you're using, click on the "Projects" button on the left.

                  Also, go to Tools -> Options -> Build & Run -> Kits to see all the compiler+Qt versions available on your computer.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nicky j
                    wrote on last edited by
                    #9

                    looks like we got Clang, GCC with Qt 5.2.0

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andreyc
                      wrote on last edited by
                      #10

                      Try, as JKSH suggested, to add @CONFIG += c++11@ to .pro file.
                      If the error will stay the same then clang (whatever version you have) does not support this particular feature of C++ 11.

                      If you will see a different error then probably the clang supports C++ 11.
                      And the error will tell you that you put override into wrong place.
                      It suppose to be in a "function declaration":http://en.cppreference.com/w/cpp/language/override and you have it in a definition.

                      [EDIT] It can be specified at function definition but only if the definition is inside a class.

                      1 Reply Last reply
                      0

                      • Login

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