Same code but Qt Creator showed error, Visual Studio didn't
-
Hi, this is my first post in the forum :)
I'm using Qt Creator 10.0.2, Qt 6.2.2 MSVC2019 static compiler.
I got a class named ProcessData it has overloaded operators like this (in Process.h header file):bool operator== (const ProcessData & rhs) const; bool operator== (const tagPROCESSENTRY32 & rhs) const; bool operator== (const tagPROCESSENTRY32W & rhs) const;
In source file (Process.cpp), I also implemented the overloaded functions there, and then the error occurred in this line:
auto & current_entry = *list[i]; if (current_entry != entries[i]){ //code }
current_entry is type of ProcessData, and entries is a vector of tagPROCESSENTRY32W, Qt Creator fails to detect it and returns this error C2678:
But VS2019 works perfectly fine:
So, what am I missing here, or this is the Creator's bug, If I'm missing something, please help me to fix it, thank you very much. I really want to use QTC to continue my work but this error slows me down for few days recently.
And in my header file, it always fades out the code like this:
Is this normal?
-
Does your project build with Qt Creator? Is this just a syntax highlighting error?
Your project should build in the same way with Qt Creator and Visual Studio.
process.h
is controversial and Qt Creator itself has had this issue:#if defined(Q_CC_MINGW) && defined(WIN_PTHREADS_H) && !defined(_INC_PROCESS) // Arrived here via <pthread.h> which wants to include <process.h> #include_next <process.h> #elif !defined(UTILS_PROCESS_H) #define UTILS_PROCESS_H
At the top of Qt Creator's
utils/process.h
. Maybe you can figure something out. -
@cristian-adam Thanks, I changed the name of the header file as well as the source file, and it didn't fade out anymore.
But the error about overloaded operator still occurs, maybe I should manually overload "!=" operator?
-
@cristian-adam My project is built with Qt Creator, but the code itself is in another project compiled with VS using Qt, and when opening that project, the code compiled without any error.
-
-
When you want to use the operator !=() you have to provide it - a compiler can not simply create the operator!=() from the operator==().
-