'QOverload' was not declared in this scope
-
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
-
@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
-
@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 . -
@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 useNULL
: https://stackoverflow.com/questions/462165/error-null-was-not-declared-in-this-scopeNote: 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
andNULL
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
withnullptr
.This article explains why you should switch to
nullptr
: https://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html -
@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...
-
@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 addCONFIG += 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.