Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtHttpServer Build Problem



  • Hey everyone,

    I'm trying to use the QtHttpServer code to embed that functionality inside a QGuiApplication that we have. I recently installed a fresh copy of Qt 5.15 with cmake and cloned the 5.15 branch of QTHttpServer. This is on Windows, so I also installed Strawberry Perl and am using VS 2019 to compile. Great, so I can get the QtHttpServer code to compile and the simple example does run. Our project uses cmake instead of qmake. So, once I built QtHttpServer, I moved the contents of bin, include, and lib to the appropriate locations in my Qt installation directory. In our cmake file, I added commands in our find_package/link to include HttpServer. Again, great, it found the modules. Now, my problem. In our program, I copied the following lines from the example,

      QHttpServer httpServer;
        httpServer.route("/", []() {
            return "Hello world";
        });
    

    When I try to build our project, I get the following errors:

    
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(74): error C2143: syntax error: missing '}' before '('
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(74): error C2059: syntax error: 'constant'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(79): error C2143: syntax error: missing ';' before '}'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(79): error C2238: unexpected token(s) preceding ';'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2255: 'friend': not allowed outside of a class definition
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2065: 'Method': undeclared identifier
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2365: 'qt_getEnumMetaObject': redefinition; previous definition was 'function'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2131: expression did not evaluate to a constant
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): note: a non-constant (sub-)expression was encountered
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2143: syntax error: missing ';' before 'noexcept'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2059: syntax error: 'noexcept'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2143: syntax error: missing ';' before '{'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2447: '{': missing function header (old-style formal list?)
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2365: 'qt_getEnumName': redefinition; previous definition was 'function'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(80): error C2059: syntax error: '}'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(81): error C2065: 'Method': undeclared identifier
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(81): error C2923: 'QFlags': 'Method' is not a valid template type argument for parameter 'Enum'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2255: 'friend': not allowed outside of a class definition
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2065: 'Methods': undeclared identifier
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2365: 'qt_getEnumMetaObject': redefinition; previous definition was 'function'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2131: expression did not evaluate to a constant
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): note: a non-constant (sub-)expression was encountered
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2143: syntax error: missing ';' before 'noexcept'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2059: syntax error: 'noexcept'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2143: syntax error: missing ';' before '{'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2447: '{': missing function header (old-style formal list?)
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2365: 'qt_getEnumName': redefinition; previous definition was 'function'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(82): error C2059: syntax error: '}'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(85): error C2270: 'url': modifiers not allowed on nonmember functions
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(86): error C2270: 'query': modifiers not allowed on nonmember functions
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(87): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(87): error C2146: syntax error: missing ';' before identifier 'method'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(88): error C2270: 'headers': modifiers not allowed on nonmember functions
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(89): error C2270: 'body': modifiers not allowed on nonmember functions
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(90): error C2270: 'remoteAddress': modifiers not allowed on nonmember functions
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(92): error C2059: syntax error: 'protected'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(93): error C2059: syntax error: 'const'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(95): error C2059: syntax error: 'private'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(97): error C2255: 'friend': not allowed outside of a class definition
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(100): error C2059: syntax error: 'const'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(103): error C2059: syntax error: '}'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrequest.h(103): error C2143: syntax error: missing ';' before '}'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(57): error C2039: 'Methods': is not a member of 'QHttpServerRequest'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(40): note: see declaration of 'QHttpServerRequest'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(56): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(57): error C2146: syntax error: missing ')' before identifier 'methods'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(56): error C3646: 'methods': unknown override specifier
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(58): error C2143: syntax error: missing ';' before '&&'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(56): error C2059: syntax error: '&&'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(56): error C2059: syntax error: ')'
    C:\Code\qthttpserver\src\httpserver\../../../qthttpserver/src/httpserver/qhttpserverrouterrule.h(56): error C2238: unexpected token(s) preceding ';'
    

    So, I'm at a loss here. The example works, but when I try to use the code inside our own program, all these errors pop up from the src files in QtHttpServer. Can anyone help me understand why? Also, it looks like these errors are from the header in the directory that I compiled QtHttpServer rather than where I moved them to in the Qt Installation directory. I don't know if that would be causing my issue? And if it is, how do I point it to the folder I copied rather than the original location? Thanks for any help!


  • Lifetime Qt Champion

    @MBor said in QtHttpServer Build Problem:

    C:\Code\qthttpserver\src\httpserver../../../qthttpserver/src/httpserver/qhttpserverrequest.h(74): error C2143: syntax error: missing '}' before '('

    Is this the first error you get?



  • Yes, it is.


  • Moderators

    What is the line that the compiler chokes at? If I check out latest 5.15 branch, line 74 should be
    a declaration inside an enum:

        DELETE  = Delete,
    

    If that's true your program, or some header files that are included before qhttpserverrequest.h, most likely defines either DELETE or Delete as preprocessor macro.

    Regarding the relative path: THis is how header files are set up if you configure a non-prefix build. Try to build Qt / qhttpserver with a prefix path.



  • You must be correct. Thank you so much! I put a #undef Delete just before including the QtHttpServer header and now everything seems to work. Unfortunately, it looks as though delete is included and redefined as part of Boost's winapi. Since it's redefined, I should be ok, but I'll go through and double check. I'll also give the prefix definition a try. Now it's off to IT since apparently my windows firewall blocks the QHttpServer code as a security risk...yay. Thanks again!


Log in to reply