Question

I'm trying to use QtWebApp to create a simple web app server, but it shows some error that i could not figure how to fix, any hint how to fix this?

here's what i've done:

= downloading QtWebApp-src.zip from http://stefanfrings.de/qtwebapp/

= compiling QtWebApp using qmake and make, completed successfully

= create a new qwtest.pro, containing:

QT       += core network
QT       -= gui
TARGET   = qwtest
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

= create source file main.cpp, containing:

#include "../v1.3.2 2014-01-08/lib/bfHttpServer/src/httplistener.h"
#include <QtCore>

class MyController: public HttpRequestHandler {
  private:
    QCoreApplication *app;
  public:
    MyController(QCoreApplication *app) : app(app) {}
    void service(HttpRequest& request, HttpResponse& response);
};

void MyController::service(HttpRequest& request, HttpResponse& response) {
    QByteArray path=request.getPath();
    QByteArray username=request.getParameter("username");
    response.setHeader("Content-Type", "text/html; charset=ISO-8859-1");
    response.setCookie(HttpCookie("myCookie","any value",600));
    response.write("<html><body>");
    response.write("Hello ");
    response.write(username);
    response.write("</body></html>");
}

int main(int argc, char *argv[]) {
    QCoreApplication* app=new QCoreApplication(argc,argv);    
    QSettings* settings=new QSettings("configfile.ini",QSettings::IniFormat,app);
    MyController* controller=new MyController(app);
    HttpListener* listener=new HttpListener(settings,controller,app);    
    return app->exec();
}

= compiling using qmake and make

/home/foo/qtwebapp/build-QtWebApp-Desktop-Debug/../v1.3.2 2014-01-08/src/main.cpp:66: undefined reference to `Startup::Startup(int, char**)'
/home/foo/qtwebapp/build-QtWebApp-Desktop-Debug/../v1.3.2 2014-01-08/src/main.cpp:67: undefined reference to `QtServiceBase::exec()'
main.o:(.data.rel.ro._ZTV9QtServiceI16QCoreApplicationE[_ZTV9QtServiceI16QCoreApplicationE]+0x28): undefined reference to `QtServiceBase::stop()'
main.o:(.data.rel.ro._ZTV9QtServiceI16QCoreApplicationE[_ZTV9QtServiceI16QCoreApplicationE]+0x30): undefined reference to `QtServiceBase::pause()'
main.o:(.data.rel.ro._ZTV9QtServiceI16QCoreApplicationE[_ZTV9QtServiceI16QCoreApplicationE]+0x38): undefined reference to `QtServiceBase::resume()'
main.o:(.data.rel.ro._ZTV9QtServiceI16QCoreApplicationE[_ZTV9QtServiceI16QCoreApplicationE]+0x40): undefined reference to `QtServiceBase::processCommand(int)'
main.o: In function `Startup::~Startup()':
/home/foo/qtwebapp/build-QtWebApp-Desktop-Debug/../v1.3.2 2014-01-08/src/startup.h:16: undefined reference to `vtable for Startup'
main.o: In function `QtService<QCoreApplication>::~QtService()':
/home/foo/qtwebapp/build-QtWebApp-Desktop-Debug/../v1.3.2 2014-01-08/lib/qtservice/src/qtservice.h:170: undefined reference to `QtServiceBase::~QtServiceBase()'
main.o:(.data.rel.ro._ZTI9QtServiceI16QCoreApplicationE[_ZTI9QtServiceI16QCoreApplicationE]+0x10): undefined reference to `typeinfo for QtServiceBase'
collect2: error: ld returned 1 exit status
Makefile:182: recipe for target 'qwtest' failed
Was it helpful?

Solution 3

I forgot to add the libs, this what i should add on the qwtest.pro file

LIBS += /home/foo/qtwebapp/qwtest/http*.o \
/home/foo/qtwebapp/qwtest/moc_*.o \
/home/foo/qtwebapp/qwtest/log*.o \
/home/foo/qtwebapp/qwtest/f*.o \
/home/foo/qtwebapp/qwtest/template*.o \
/home/foo/qtwebapp/qwtest/du*.o \
/home/foo/qtwebapp/qwtest/request*.o \
/home/foo/qtwebapp/qwtest/session*.o \
/home/foo/qtwebapp/qwtest/static*.o 

OTHER TIPS

Your project file must include the sources of the bfHttpServer classes. Take a look at the project file that comes with the QtWebapp example, there you see how to include them.

include(lib/bfHttpServer/src/bfHttpServer.pri)

main.cpp:66: undefined reference to `Startup::Startup(int, char**)'

The main.cpp file that you compiled uses the Startup class from the example application. But the main.cpp that you posted above does not.

I assume you are compiling the wrong directory. Or maybe you just have to call qmake to update some files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top