Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Careful with "interface" keyword with Qt on windows
i'm compiling on windows 4.8.2 (msvc2010) and the QNetWorkInterface is not define :(
After some little search i think that in my Qt version the QT_NO_NETWORKINTERFACE is define somewhere.
somebody knows where is define ? in the configure ?
thanks in advance
lgeyer last edited by
Such things a usually defined in qconfig.h. But for a standard installation this should be not the case. Are you sure that you haven't just forgot <code>QT += network</code> in your .pro?
for this piece of code i obtain :
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
this error :
@ file.cpp(51) : error C2332: 'struct' : missing tag name
file.cpp(51) : error C2011: '<unnamed-tag>' : 'enum' type r
c:\qt\4.8.2vs\include\qtgui../../src/gui/styles/qs60style.h(65) : see d
eclaration of '<unnamed-tag>'
src\caisse\mcaissemetrics.cpp(51) : error C2236: unexpected 'struct' '<unnamed-t
ag>'. Did you forget a ';'? @
or if i replace #include <QNetworkInterface> by #include <QtNetwork> it compiles fine.
i have to specify that it compiles fine under linux g++.
any idea ?
ps : QT_NO_NETWORKINTERFACE was a red herring
bq. Such things a usually defined in qconfig.h. But for a standard installation this should be not the case. Are you sure that you haven’t just forgot QT += network in your .pro?
yes, it compiles fine under my linux machine but effectively this one is under 4.7.1
lgeyer last edited by
Might be a MSVC quirk, because this works as expected for MinGW.
I think the least time consuming solution is to go through the includes from QtNetwork and to find out which one enables the code to compile (just include them separately one by one).
ok i will try when i will have times. (i will post here the result)
thanks for reply.
Why is qs60style included on a windows platform? That style is for symbian phones AFAIK.
i agree with you but i don't know i just do a classical configure.
So did you check what is including qs60style.h?
bq. I think the least time consuming solution is to go through the includes from QtNetwork and to find out which one enables the code to compile (just include them separately one by one).
is this one
if i have
but i think is more complicated because if i do a simple example it works with only qnetworkinterface.
after some search i have found the explanation of the problem and Qt is not the cause.
this is a little exemple that don't compile
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
in fact if you include <qt_windows.h> and in some case if you name a variable interface you obtain this error of compilation (it is very bad :( ) :
@ main.cpp(10) : error C2332: 'struct' : missing tag name main.cpp(10) : error C2011: '<unnamed-tag>' : 'enum' type redefinition c:\qt\4.8.2vs\include\qtcore../../src/corelib/global/qglobal.h(2122) : see declaration of '<unnamed-tag>' main.cpp(10) : error C2236: unexpected 'struct' '<unnamed-tag>'. Did you forget a ';'?
As you can see it is no longer qs60style.h but qglobal.h
after som search i found the file witch declare the interface keyword it's :
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\objbase.h
#define STRUCT struct
#define interface STRUCT
The only thing that i don't understand is why if we include <qnetworkconfigmanager.h> the error disapear. maybe a define in this file or its include ?
but to finish i would say never use the interface keyword for a variable name.
i have found the include that undef "interface" (i don't know if it's a good idea).
it's qnetworkconfiguration.h line 46 :
#if defined(Q_OS_WIN) && defined(interface)
it's realy strange because it is not use after in the file.
i think it is a dangerous behaviour for windows 's platform users.
moodboom last edited by
WOW I cannot believe someone else had this same problem, and THANKS for posting it. I switched from Qt4 to Qt5, Visual Studio 2010 to 2013... and BOOM, this problem popped up for me. I have been rewriting and slinging code to figure out what the problem was. I changed a VARIABLE NAME from interface to xinterface, and all of a sudden everything compiles. Thanks for saving me a TON of time! :-)