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. 'QOverload' was not declared in this scope

'QOverload' was not declared in this scope

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    What did I miss in my code ?

      #include <QtGlobal>
    
        connect(ui->list,                                   // list_widget_1,
                &QListWidget::itemClicked,
                ui->list_2,                                // list_widget_2,
                QOverload<QListWidgetItem*>::of(&QListWidget::addItem));
    
    c/media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/device.cpp:136: error: 'QOverload' was not declared in this scope
                 QOverload<QListWidgetItem*>::of(&QListWidget::addItem));
                 ^ode_text
    
    Gojir4G 1 Reply Last reply
    0
    • A Anonymous_Banned275

      What did I miss in my code ?

        #include <QtGlobal>
      
          connect(ui->list,                                   // list_widget_1,
                  &QListWidget::itemClicked,
                  ui->list_2,                                // list_widget_2,
                  QOverload<QListWidgetItem*>::of(&QListWidget::addItem));
      
      c/media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/device.cpp:136: error: 'QOverload' was not declared in this scope
                   QOverload<QListWidgetItem*>::of(&QListWidget::addItem));
                   ^ode_text
      
      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @AnneRanch Hi, This may caused by the C++ version you are using. The doc says:

      qOverload() requires C++14 enabled. In C++11-only code, the helper classes QOverload, QConstOverload, and QNonConstOverload can be used directly

      jsulmJ A 2 Replies Last reply
      1
      • Gojir4G Gojir4

        @AnneRanch Hi, This may caused by the C++ version you are using. The doc says:

        qOverload() requires C++14 enabled. In C++11-only code, the helper classes QOverload, QConstOverload, and QNonConstOverload can be used directly

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Gojir4 OP uses QOverload.

        @AnneRanch What Qt version do you use?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        aha_1980A 1 Reply Last reply
        1
        • jsulmJ jsulm

          @Gojir4 OP uses QOverload.

          @AnneRanch What Qt version do you use?

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @AnneRanch

          And to add to @jsulm: Is your compiler C++11 enabled, and do you have CONFIG+=C++11 in your .pro file?

          Regards

          Qt has to stay free or it will die.

          1 Reply Last reply
          1
          • Gojir4G Gojir4

            @AnneRanch Hi, This may caused by the C++ version you are using. The doc says:

            qOverload() requires C++14 enabled. In C++11-only code, the helper classes QOverload, QConstOverload, and QNonConstOverload can be used directly

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by Anonymous_Banned275
            #5

            @Gojir4 I;ll check the compiler version.
            My guess is C++ 11 so far had no reason to check it.

            I am not sure I really need the overload.

            I did read the doc, but I did not get what does "using directly " means.

            After adding

            added CONFIG+=C++11 2/1/2/2020

            CONFIG+=C++11

            I get this weird error

            /media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/service.h:54: error: 'NULL' was not declared in this scope
            #define nullptr NULL
            ^
            can I add
            #define NULL
            to .pro file instead to my "project common" header?
            It cannot work / be added directly since "#" is a comment symbol in project file .

            JKSHJ 1 Reply Last reply
            0
            • A Anonymous_Banned275

              @Gojir4 I;ll check the compiler version.
              My guess is C++ 11 so far had no reason to check it.

              I am not sure I really need the overload.

              I did read the doc, but I did not get what does "using directly " means.

              After adding

              added CONFIG+=C++11 2/1/2/2020

              CONFIG+=C++11

              I get this weird error

              /media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/service.h:54: error: 'NULL' was not declared in this scope
              #define nullptr NULL
              ^
              can I add
              #define NULL
              to .pro file instead to my "project common" header?
              It cannot work / be added directly since "#" is a comment symbol in project file .

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @AnneRanch said in 'QOverload' was not declared in this scope:

              I get this weird error

              /media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/service.h:54: error: 'NULL' was not declared in this scope

              It's expected, not weird.

              C++11 encourages all programmers to move away from NULL. One of the ways it does this is by making it harder to use NULL: https://stackoverflow.com/questions/462165/error-null-was-not-declared-in-this-scope

              Note: Whenever you get an error message that seems weird, just copy and paste that message into a search engine. Chances are someone has already explained online how to handle it.

              can I add
              #define NULL
              to .pro file instead to my "project common" header?

              You can't (and shouldn't) try something like that. nullptr and NULL are standard components of C++ so you can break things by trying to define them manually.

              Just remove the custom #defines in your code and replace all uses of NULL with nullptr.

              This article explains why you should switch to nullptr: https://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html

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

              A 1 Reply Last reply
              2
              • JKSHJ JKSH

                @AnneRanch said in 'QOverload' was not declared in this scope:

                I get this weird error

                /media/f/QT/Qt/QT/qtconnectivity/examples/bluetooth/CAT_BT_18112020/service.h:54: error: 'NULL' was not declared in this scope

                It's expected, not weird.

                C++11 encourages all programmers to move away from NULL. One of the ways it does this is by making it harder to use NULL: https://stackoverflow.com/questions/462165/error-null-was-not-declared-in-this-scope

                Note: Whenever you get an error message that seems weird, just copy and paste that message into a search engine. Chances are someone has already explained online how to handle it.

                can I add
                #define NULL
                to .pro file instead to my "project common" header?

                You can't (and shouldn't) try something like that. nullptr and NULL are standard components of C++ so you can break things by trying to define them manually.

                Just remove the custom #defines in your code and replace all uses of NULL with nullptr.

                This article explains why you should switch to nullptr: https://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html

                A Offline
                A Offline
                Anonymous_Banned275
                wrote on last edited by Anonymous_Banned275
                #7

                @JKSH So C++ examples of Qt complains about missing null pointer, hence I added #define . Now C++11 complain about it lead me to believe NULL is not even defined.
                Funny part NULL is never (openly) used in Qt examples.

                "just copy and paste that message into a search engine"

                FYI my favorite no-nos in TECHNICAL forum posts:

                ...Google it ...
                ...RTFM...
                ...you needs to study...

                I instead prefer to discuss technical stuff in forum and I believe the "no-nos" are pretty given - so why bother to post them?

                That is my opinion , so go ahead and ban me...

                JKSHJ 1 Reply Last reply
                0
                • A Anonymous_Banned275

                  @JKSH So C++ examples of Qt complains about missing null pointer, hence I added #define . Now C++11 complain about it lead me to believe NULL is not even defined.
                  Funny part NULL is never (openly) used in Qt examples.

                  "just copy and paste that message into a search engine"

                  FYI my favorite no-nos in TECHNICAL forum posts:

                  ...Google it ...
                  ...RTFM...
                  ...you needs to study...

                  I instead prefer to discuss technical stuff in forum and I believe the "no-nos" are pretty given - so why bother to post them?

                  That is my opinion , so go ahead and ban me...

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by JKSH
                  #8

                  @AnneRanch said in 'QOverload' was not declared in this scope:

                  Funny part NULL is never (openly) used in Qt examples.

                  That's a good thing. NULL should not be used anymore, as explained in my previous post and in the links I provided. Does that make sense?

                  So C++ examples of Qt complains about missing null pointer

                  That's because your project was not being compiled with C++11 compliance enabled.

                  What compiler version and Qt version are you using? Recent versions should already have C++11 (or even C++14/C++17) enabled by default, so they should all know nullptr by default even if you don't add CONFIG += C++11.

                  hence I added #define .

                  Enabling C++11 to enable the native nullptr keyword is better than adding a custom #define.

                  That is my opinion , so go ahead and ban me...

                  You didn't do anything wrong so nobody is gonna ban you.

                  "just copy and paste that message into a search engine"

                  FYI my favorite no-nos in TECHNICAL forum posts:

                  ...Google it ...
                  ...RTFM...
                  ...you needs to study...

                  I instead prefer to discuss technical stuff in forum

                  I agree with you that "Google it"/"RTFM"/"you needs to study" are useless as standalone responses. But, I explained/discussed the error message before I mentioned search engines, didn't I?

                  Google and discussions are not mutually exclusive. For example: "I got this error message, 'ABC'. I found this article on Google which says 'DEF' but it doesn't make sense to me because I thought 'XYZ'. Can you please help shed some light on this?" -- this is a good way to start a discussion.

                  I believe the "no-nos" are pretty given - so why bother to post them?

                  Some people genuinely don't think of using search engines. I don't make assumptions on what people do or don't know, so I post the recommendation just in case. I believe that quick searches help us to understand the problem better.

                  Anyway, I've taken note of your personal preferences so I won't bring up Google with you again.

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

                  1 Reply Last reply
                  5

                  • Login

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