[SOLVED] Careful with "interface" keyword with Qt on windows
-
wrote on 27 Jul 2012, 09:50 last edited by
Hello,
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
-
wrote on 27 Jul 2012, 12:21 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?
-
wrote on 27 Jul 2012, 13:08 last edited by
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
edefinition
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
-
wrote on 27 Jul 2012, 13:10 last edited by
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
-
wrote on 27 Jul 2012, 13:46 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).
-
wrote on 27 Jul 2012, 13:54 last edited by
ok i will try when i will have times. (i will post here the result)
thanks for reply.
-
wrote on 27 Jul 2012, 14:48 last edited by
Why is qs60style included on a windows platform? That style is for symbian phones AFAIK.
-
wrote on 27 Jul 2012, 14:51 last edited by
i agree with you but i don't know i just do a classical configure.
-
wrote on 27 Jul 2012, 15:06 last edited by
So did you check what is including qs60style.h?
-
wrote on 27 Jul 2012, 15:49 last edited by
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
#include "qnetworkconfigmanager.h"if i have
#include "qnetworkinterface.h"
#include "qnetworkconfigmanager.h"it works.
but i think is more complicated because if i do a simple example it works with only qnetworkinterface.
hummm strange.
-
wrote on 30 Jul 2012, 06:08 last edited by
hello,
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
@
#include <QCoreApplication>
#include <QUdpSocket>
#include <qt_windows.h>
//#include <qnetworkconfigmanager.h>
#include <QNetworkInterface>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkInterface interface;return a.exec();
}
@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 STRUCTThe 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.
-
wrote on 1 Aug 2012, 15:00 last edited by
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)
#undef interface
#endif
@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. -
wrote on 9 Jan 2014, 21:37 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! :-)