Skip to content
  • 0 Votes
    6 Posts
    861 Views
    R

    After playing around using postman I found the issue.

    When sending a Bearer: "" or Bearer: "xxxxxx" token, the server returns "Authentication Required".

    But when sending no Bearer token or an empty Bearer: it works fine.

    So when logging in; no token must be supplied else it tries to authenticate against that token instead of correctly generating a new one provided you submitted valid credentials in the JSON body.

    Seems a bit odd to me, but ok.

  • 0 Votes
    12 Posts
    739 Views
    J

    @JonB That especific array allows me to read info coming from an arduino connected to my raspberry in where I'm doing all of this so the arduino sents me the dintance from a second sensor it is Just a number for example 11 or 113 or 5 is similar to What I'm trying to do with the ESP8266 but via wifi. The arduino part is always woking no matter how much time I have the gui running so I kinda figured out my mistake must be in the way I get the value from the hmtl page wich brings me to the QNetworkAccessManager.

  • 0 Votes
    2 Posts
    192 Views
    C

    Does your QNetworkAccessManager emit encrypted() or sslErrors() signals? If so, what errors?

  • 0 Votes
    1 Posts
    228 Views
    No one has replied
  • 0 Votes
    2 Posts
    384 Views
    SGaistS

    Hi,

    A minimal compilable example would be nice for the bug report.

    Did you also check with Qt 5.15.0 and 5.15.1 ? Just in case it something that changed with 5.15.2.

  • 0 Votes
    15 Posts
    4k Views
    R

    The solution that worked for me was to pick the network adapter and then look through its list of IP addresses to pick one to bind the socket to based on given criteria as suggested by @kshegunov. I've updated the example project:
    https://github.com/rtavakko/MulticastServer

  • 0 Votes
    3 Posts
    1k Views
    Pablo J. RoginaP

    @BikashRDas said in QNetworkConfiguration and QNetworkConfigurationManager alternatives for Qt 5.15.2:

    I am using Qt 5.15.2 enterprise edition

    Is that version backed by a commercial license from Qt?
    If so, you may want to ask for help from Qt support directly

  • 0 Votes
    2 Posts
    369 Views
    SGaistS

    Hi,

    Usually you don't store the reply but rather connect its signals to lambdas, do the processing there and then call deleteLater on it once you are done.

  • 0 Votes
    17 Posts
    16k Views
    D

    @dheerendra At this point, we are fairly certain that the problem is in the main thread code. I have uploaded the main thread code in the previous comment. Please suggest any necessary changes that could solve the issue. thank you.

  • 0 Votes
    5 Posts
    2k Views
    SGaistS

    The problem with such an example is that it doesn't allow to replicate your problem correctly and triggers others that are not related to yours thus it's not possible to offer sensible help.

  • 0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi and welcome to devnet,

    Maybe QNetworkProxy might something.

    Hope it helps

  • 0 Votes
    4 Posts
    1k Views
    SGaistS

    You don't need to simulate, just have something that small and exhibit the same behavior.

  • 0 Votes
    4 Posts
    3k Views
    T

    Since you seem to have some problems with QRegularExpression (Read the documentation! It's the best I have ever seen!), I will give you a small example. I happen to be using something like this in a program I am working on:

    QRegularExpression re("<img (?<junk>.*?) src=(?<path>\\S+?) (?<junk2>.*?)>"), QRegularExpression::CaseInsensitiveOption);

    The ?<name>-blocks are there to provide named captures in the matches. The first one is called junk - it is allowed to contain anything but the "src"-attribute (.*? matches any sign in a "lazy" manner). junk2 behaves equivalently; if you don't need to capture (i.e. store for later access) these groups, you could simplify the expression a bit.
    path will be storing the download-link for the image. \\S will match every non-whitespace character, +? means that there has to be at least one character like that. You will have to adapt to path including "-signs, depends on your specific case.

    Here a bit of code I copied and slightly modified from the documentation for QRegularExpression:

    QString s = "<img style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex;\" src=http://en.wikitolearn.org/index.php?title=Special:MathShowImage&hash=2af9544640fe8b97375512027efaaccd&mode=mathml>"; QRegularExpressionMatch match = re.match(s); while (match.hasMatch()) { QString junk = match.captured("junk"); // junk == style=\"background-repeat: no-repeat; background-size: 100% 100%; vertical-align: -0.838ex;height: 2.843ex;\" QString junk2 = match.captured("junk2"); // junk2 == "" QString path = match.captured("path"); // path == http://en.wikitolearn.org/index.php?title=Special:MathShowImage&hash=2af9544640fe8b97375512027efaaccd&mode=mathml }

    Hand in your html-file instead of s, take care of some minute details (path enclosed in " or not? Maybe no space before junk2? etc.), and then you should be able to do whatever you want with your links.
    I hope that gets you started.

  • 0 Votes
    3 Posts
    3k Views
    S

    It's a mistake when I copy the code from other place.

    Here are the exact code below that I just write for this network test.
    The bigger the count of request sent in a loop, the more consumed virtual memory of this program.
    And after finished all of these http requests, the Virtual Memory of this program did not reduce.
    However, when I add a qWait(1) between every request, the memory will not goes up when the number of sent requests grows. But the memory still doesn't go down when I delete everything I used to access network.
    It seems when concurrently create and send a large amount of http requests through QNetworkAccessManager, the memory leakage will happen.

    //Header**
    #ifndef NETWORK_H
    #define NETWORK_H

    #include <QObject>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QUrl>
    #include <QTest>

    class NetWork : public QObject
    {
    Q_OBJECT
    private:
    explicit NetWork(QObject *parent = 0);

    public:
    static NetWork *Instance();

    void Post(const QUrl &url, const QByteArray content); void Get(const QUrl &url); void Clean(); void Print(); QNetworkAccessManager *Manager();

    signals:

    public slots:
    void SlotPostFinished();
    void SlotCountDestroyed();

    private:
    static NetWork *_network;
    QNetworkAccessManager *_manager;

    public:
    qint32 _countOk, _countError, _countSent, _countDestroyed;
    };

    class UnitTest_Network : public QObject{
    Q_OBJECT
    public:
    explicit UnitTest_Network(QObject *parent = 0);

    private slots:
    void test10ps();
    void test10ps_data();
    };

    #endif // NETWORK_H

    //CPP
    #include "network.h"

    NetWork::NetWork(QObject *parent) :
    QObject(parent)
    {
    _manager = new QNetworkAccessManager(this);
    }

    NetWork *NetWork::_network = NULL;
    NetWork *NetWork::Instance()
    {
    if(_network == NULL){
    _network = new NetWork();
    }
    return _network;
    }

    void NetWork::Post(const QUrl &url, const QByteArray content)
    {
    QNetworkRequest request(url);

    request.setRawHeader("Content-Type", "application/json"); QNetworkReply *reply = _manager->post(request, content); connect(reply, SIGNAL(finished()), this, SLOT(SlotPostFinished())); connect(reply, SIGNAL(destroyed()), this, SLOT(SlotCountDestroyed()));

    }

    void NetWork::Get(const QUrl &url)
    {
    QNetworkRequest request(url);

    request.setRawHeader("Content-Type", "application/json"); QNetworkReply *reply = _manager->get(request); connect(reply, SIGNAL(finished()), this, SLOT(SlotPostFinished()), Qt::DirectConnection); connect(reply, SIGNAL(destroyed()), this, SLOT(SlotCountDestroyed()));

    }

    void NetWork::Clean()
    {
    _countOk = 0;
    _countError = 0;
    _countSent = 0;
    _countDestroyed = 0;
    }

    void NetWork::Print()
    {
    qDebug("10 ps:\t Sent = %d, Ok = %d, Error = %d, Destroyed = %d",
    _countSent, _countOk, _countError, _countDestroyed);
    qApp->processEvents();
    }

    QNetworkAccessManager *NetWork::Manager()
    {
    return _manager;
    }

    void NetWork::SlotPostFinished()
    {
    QNetworkReply reply = (QNetworkReply)sender();
    qint32 statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
    if(!reply->error()){
    _countOk++;
    }
    else{
    _countError++;
    }
    reply->readAll();
    reply->abort();
    reply->close();
    reply->deleteLater();
    }

    void NetWork::SlotCountDestroyed()
    {
    _countDestroyed++;
    }

    void UnitTest_Network::test10ps()
    {

    }

    void UnitTest_Network::test10ps_data()
    {
    QTest::addColumn<qint32>("hehe");
    NetWork::Instance()->Clean();
    qDebug("Test 10 ps ...");

    qint32 count = 500; qDebug("Starting ..."); QTest::qWait(1000); for(int j=0; j<10; j++){ for(int i=0; i<count; i++){ NetWork::Instance()->Post(QString("http://192.168.0.90/rest/Logs/"), QByteArray("{\"reserve\" : \"\", \"logTime\" : 1410865245827, \"machineId\" : \"0023\", \"operationCode\" : \"x\", \"deviceNum\" : \"b\", \"deviceAttribute\" : \"5\",\"parameter\" :\"0624\", \"checksum\" : -111, \"serialNum\" : \"92bb\"}")); NetWork::Instance()->_countSent++;

    // QTest::qWait(1);
    // qApp->processEvents();
    }
    qDebug("LOOP No.%d", j);
    }

    while(1){ if(NetWork::Instance()->_countSent == NetWork::Instance()->_countError + NetWork::Instance()->_countOk) break; NetWork::Instance()->Print(); QTest::qWait(5000); } qDebug("delete manager ..."); QTest::qWait(5000); NetWork::Instance()->Manager()->deleteLater(); qDebug("wait ..."); QTest::qWait(5000); qDebug("delete network ..."); NetWork::Instance()->deleteLater(); QTest::qWait(5000); qDebug("End ..."); QTest::qWait(10000);

    }

    UnitTest_Network::UnitTest_Network(QObject *parent)
    {
    }

    QTEST_MAIN(UnitTest_Network)

  • 0 Votes
    8 Posts
    3k Views
    SGaistS

    Just to be sure: it fails to build on Windows even if you use one of the official package ?

  • 0 Votes
    2 Posts
    3k Views
    UndeadBlowU

    Ok, i got it:

    // Disambiguate overloaded member function below with static cast connect(socket, static_cast<void (QTcpSocket::*) (QAbstractSocket::SocketError)>(&QTcpSocket::error), this, &Network::socketErrorSlot);

    I think that deserves to be in bugtracker, isn't it? Not good idea to implement new notation and use the same names for method and signal.

  • 0 Votes
    7 Posts
    3k Views
    P

    Just a status update for anybody interested and for documentation.
    The machines running Ubuntu 14.10 Kernel 3.16 still running since yesterday. Machines with Kernel 4.0.1 crashed after eg. 2 hours. I now downgraded to a lts version of the Kernel 3.14 on those machines crashing.

    In two weeks, when this project is over, i'll try to extract and provide a minimal version of this and try to investigate this further. for now i only try to find a system configuration that just simply work :( i'll update this post accordingly.

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    1 Posts
    722 Views
    No one has replied
  • 0 Votes
    6 Posts
    3k Views
    M

    I suggest to use the readyRead() signal to be notified when some data arrive on the socket