Last active
August 29, 2015 14:25
-
-
Save rhaamo/3587dd8b2a225d78ed9a to your computer and use it in GitHub Desktop.
This file contains 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
➜ lib git:(plugins) ✗ make | |
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -Werror -O2 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I. -I../main -I../../../../Qt/5.5/clang_64/lib/QtNetwork.framework/Headers -I../../../../Qt/5.5/clang_64/lib/QtCore.framework/Headers -Itmp/moc -I../../../../Qt/5.5/clang_64/mkspecs/macx-clang -F/Users/dashie/Qt/5.5/clang_64/lib -o tmp/obj/httpcommon.o httpcommon.cpp | |
httpcommon.cpp:41:14: error: no matching member function for call to 'connect' | |
QObject::connect(reply, SIGNAL(finished()), &waitLoop, SLOT(quit())); | |
~~~~~~~~~^~~~~~~ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:196:36: note: candidate | |
function not viable: cannot convert argument of incomplete type 'QNetworkReply *' to | |
'const QObject *' | |
static QMetaObject::Connection connect(const QObject *sender, const char *signal, | |
^ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:199:36: note: candidate | |
function not viable: cannot convert argument of incomplete type 'QNetworkReply *' to | |
'const QObject *' | |
static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal, | |
^ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:475:41: note: candidate | |
function not viable: no known conversion from 'HTTPCommon' to 'const QObject' for object | |
argument | |
inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal, | |
^ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:213:43: note: candidate | |
template ignored: substitution failure [with Func1 = const char *, Func2 = const char *]: | |
no type named 'Object' in 'QtPrivate::FunctionPointer<const char *>' | |
...QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object ... | |
^ ~~~~~~ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:254:13: note: candidate | |
template ignored: substitution failure [with Func1 = const char *, Func2 = const char *]: | |
implicit instantiation of undefined template 'QtPrivate::QEnableIf<false, | |
QMetaObject::Connection>' | |
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Fun... | |
^ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:293:13: note: candidate | |
template ignored: substitution failure [with Func1 = const char *, Func2 = const char *]: | |
no type named 'Object' in 'QtPrivate::FunctionPointer<const char *>' | |
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Fun... | |
^ ~~~~~~ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:245:13: note: candidate | |
function template not viable: requires 3 arguments, but 4 were provided | |
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Fun... | |
^ | |
/Users/dashie/Qt/5.5/clang_64/lib/QtCore.framework/Headers/qobject.h:285:13: note: candidate | |
function template not viable: requires 3 arguments, but 4 were provided | |
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Fun... | |
^ | |
httpcommon.cpp:45:26: error: member access into incomplete type 'QNetworkReply' | |
int errorCode = reply->error(); | |
^ | |
../../../../Qt/5.5/clang_64/lib/QtNetwork.framework/Headers/qnetworkaccessmanager.h:54:7: note: | |
forward declaration of 'QNetworkReply' | |
class QNetworkReply; | |
^ | |
httpcommon.cpp:58:5: error: deleting pointer to incomplete type 'QNetworkReply' may cause | |
undefined behavior [-Werror,-Wdelete-incomplete] | |
delete reply; | |
^ ~~~~~ | |
../../../../Qt/5.5/clang_64/lib/QtNetwork.framework/Headers/qnetworkaccessmanager.h:54:7: note: | |
forward declaration of 'QNetworkReply' | |
class QNetworkReply; | |
^ | |
3 errors generated. | |
make: *** [tmp/obj/httpcommon.o] Error 1 |
This file contains 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 "httpcommon.h" | |
#include <QNetworkAccessManager> | |
#include <QNetworkRequest> | |
#include <QString> | |
#include <QUrl> | |
#include <QEventLoop> | |
#include <QHash> | |
#include <QObject> | |
/** | |
* @brief Generic function for external HTTP Requests | |
* | |
* @param[in] server Server URI | |
* @param[in] params QUrl parameters | |
* @param[in] type Type enum | |
* | |
* @return { description_of_the_return_value } | |
*/ | |
HTTPCommon::httpResponse HTTPCommon::request(QString server, QUrl params, int type) { | |
QString params_array = params.query(); | |
httpResponse response = HTTPCommon::responseObject; | |
response.type = type; | |
response.params = params; | |
response.server = server; | |
QNetworkRequest url; | |
url.setUrl(QUrl(server)); | |
QEventLoop waitLoop; | |
QNetworkAccessManager * connection = new QNetworkAccessManager(); | |
QNetworkReply *reply; | |
if (type == POST) { | |
reply = connection->post(url, params_array.toUtf8()); | |
} else if (type == GET) { | |
reply = connection->get(url); | |
} | |
QObject::connect(reply, SIGNAL(finished()), &waitLoop, SLOT(quit())); | |
waitLoop.exec(); | |
int errorCode = reply->error(); | |
QString replyValue; | |
if (errorCode != 0){ | |
// Show Error Message | |
replyValue = "some error wtf"; | |
} | |
else{ | |
// Parse "reply" | |
replyValue = "parse reply here"; | |
} | |
delete connection; | |
delete reply; | |
return response; | |
} |
This file contains 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 HTTPCOMMON_H | |
#define HTTPCOMMON_H | |
#include <QString> | |
#include <QUrl> | |
#include <QUrlQuery> | |
class HTTPCommon { | |
public: | |
enum RequestType { INVALID, GET, POST, POSTRAW }; | |
struct httpResponse { | |
int type; | |
int errorCode; | |
QUrl params; | |
QString server; | |
QString reply; | |
} responseObject; | |
httpResponse request(QString server, QUrl params, int type); | |
}; | |
#endif // HTTPCOMMON_H | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment