Last active
December 20, 2015 14:38
-
-
Save paulbarbu/6147682 to your computer and use it in GitHub Desktop.
QPluginLoader question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtPlugin> | |
#include "squarehttprequesthandler.h" | |
Q_EXPORT_PLUGIN2(squarehttprequesthandler, SquareHTTPRequestHandler) | |
SquareHTTPRequestHandler::SquareHTTPRequestHandler() | |
{ | |
} | |
void SquareHTTPRequestHandler::createResponse() | |
{ | |
HTTPResponse response; | |
if("GET" != requestData.method || !requestData.url.hasQueryItem("a")){ | |
response.setStatusCode(400); | |
response.setReasonPhrase("Bad Request"); | |
emit responseWritten(response); | |
emit endOfWriting(); | |
return; | |
} | |
response.setStatusCode(200); | |
response.setReasonPhrase("OK"); | |
QString numToSquare = requestData.url.queryItemValue("a"); | |
QString body; | |
bool ok; | |
double n = numToSquare.toDouble(&ok); | |
if(!ok){ | |
response.setBody("a-ul trebuie sa fie numar!\n"); | |
} | |
else{ | |
response.setBody(numToSquare + "^2 = " + QString::number(n*n) + "\n"); | |
} | |
emit responseWritten(response); | |
emit endOfWriting(); | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------- | |
# | |
# Project created by QtCreator 2013-08-03T20:54:55 | |
# | |
#------------------------------------------------- | |
QT -= gui | |
TARGET = squarehttprequesthandler | |
TEMPLATE = lib | |
DEFINES += SQUAREHTTPREQUESTHANDLER_LIBRARY | |
SOURCES += squarehttprequesthandler.cpp | |
HEADERS += squarehttprequesthandler.h\ | |
squarehttprequesthandler_global.h | |
INCLUDEPATH += ../http-server | |
unix:!symbian { | |
maemo5 { | |
target.path = /opt/usr/lib | |
} else { | |
target.path = /usr/lib | |
} | |
INSTALLS += target | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QLibraryPrivate::loadPlugin failed on "/path/to/libhandler.so.1.0.0" : "Cannot load library /path/to/libhandler.so.1.0.0: (/path/to/libhandler.so.1.0.0: undefined symbol: _ZNK18HTTPRequestHandler10metaObjectEv)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef HTTPREQUESTHANDLER_H | |
#define HTTPREQUESTHANDLER_H | |
#include <QObject> | |
#include "httprequest.h" | |
#include "httpresponse.h" | |
class HTTPRequestHandler : public QObject | |
{ | |
Q_OBJECT | |
public: | |
HTTPRequestHandler(); | |
HTTPRequestHandler(const HTTPRequest &r) : requestData(r) {} | |
virtual ~HTTPRequestHandler() {} | |
virtual void createResponse()=0; | |
void setRequestData(const HTTPRequest &r){ | |
requestData = r; | |
} | |
protected: | |
HTTPRequest requestData; | |
signals: | |
void responseWritten(HTTPResponse &response); | |
void endOfWriting(); | |
}; | |
Q_DECLARE_INTERFACE(HTTPRequestHandler, "http-daemon.HTTPRequestHandler/1.0") | |
#endif // HTTPREQUESTHANDLER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment