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. [SOLVED] Careful with "interface" keyword with Qt on windows
QtWS25 Last Chance

[SOLVED] Careful with "interface" keyword with Qt on windows

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 10.2k 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.
  • L Offline
    L Offline
    le-roy_a
    wrote on 27 Jul 2012, 09:50 last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 27 Jul 2012, 12:21 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        le-roy_a
        wrote on 27 Jul 2012, 13:08 last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          le-roy_a
          wrote on 27 Jul 2012, 13:10 last edited by
          #4

          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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on 27 Jul 2012, 13:46 last edited by
            #5

            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).

            1 Reply Last reply
            0
            • L Offline
              L Offline
              le-roy_a
              wrote on 27 Jul 2012, 13:54 last edited by
              #6

              ok i will try when i will have times. (i will post here the result)

              thanks for reply.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tobias.hunger
                wrote on 27 Jul 2012, 14:48 last edited by
                #7

                Why is qs60style included on a windows platform? That style is for symbian phones AFAIK.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  le-roy_a
                  wrote on 27 Jul 2012, 14:51 last edited by
                  #8

                  i agree with you but i don't know i just do a classical configure.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on 27 Jul 2012, 15:06 last edited by
                    #9

                    So did you check what is including qs60style.h?

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      le-roy_a
                      wrote on 27 Jul 2012, 15:49 last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        le-roy_a
                        wrote on 30 Jul 2012, 06:08 last edited by
                        #11

                        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&#40;&#41;;
                        

                        }
                        @

                        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.

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          le-roy_a
                          wrote on 1 Aug 2012, 15:00 last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            moodboom
                            wrote on 9 Jan 2014, 21:37 last edited by
                            #13

                            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! :-)

                            1 Reply Last reply
                            0

                            • Login

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