本文介绍了如何创建QtWebApp应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用QtWebApp
创建一个简单的Web应用程序服务器,但是它显示了一些错误,我无法解决该问题,也没有任何提示如何解决此问题?
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?
这是我所做的:
=从 http://stefanfrings.de/qtwebapp/
=使用qmake
和make
编译QtWebApp
,成功完成
= compiling QtWebApp
using qmake
and make
, completed successfully
=创建一个新的qwtest.pro
,其中包含:
= create a new qwtest.pro
, containing:
QT += core network
QT -= gui
TARGET = qwtest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
=创建源文件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();
}
=使用qmake
和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
推荐答案
我忘记添加库,这是我应该在qwtest.pro
文件上添加的
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
这篇关于如何创建QtWebApp应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!