Error on my application: (process:9105): GLib-ERROR **: Creating pipes for GWakeup: Too many open files



  • Well I think it's about threads, the limitation os System!
    But I can't find the problem!

    I think the problem is here:

    #include "restservices.h"
    
    RestServices::RestServices(QObject *parent) : QObject(parent)
    {
    
    }
    
    void RestServices::send(QString data)
    {    
        QStringList lista= data.split("$", QString::SkipEmptyParts);
        for (int i=0; i<lista.size(); i++) {
            qDebug() << "$" << lista.at(i);
            sendRequest("$" + lista.at(i));
        }
    }
    void RestServices::sendRequest(QString data)
    {
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);
        QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), SLOT(slotRequestFinished(QNetworkReply *)));
        QNetworkRequest request;
        request.setUrl(QUrl("http://192.168.25.105:9763/CronoboxServer/rest/data/dados"));
        request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
        QNetworkReply *reply = 0;
        reply = manager->post(request, data.toUtf8());
    }
    
    void RestServices::slotRequestFinished(QNetworkReply *reply)
    {
        if (reply->error() > 0) {
            qDebug() << reply->errorString();
        } else {
            qDebug() << "Retornou: " << reply->readAll();
        }
    }
    

    So when I call to many times the method "send" I got error " GLib-ERROR **: Creating pipes for GWakeup: Too many open files".
    I think that is about Threads, but I can't find a Way to avoid this problem!
    Can anyone help me?



  • I remove the line:
    ´´´
    reply = manager->post(request, data.toUtf8());
    ´´´
    And them stop to crash the app...



  • This post is deleted!


  • I see this at log output:

    Erro: "Out of resources"

    ´´´
    void RestServices::slotRequestFinished(QNetworkReply *reply)
    {
    if (reply->error() > 0) {
    qDebug() << "Erro: " << reply->errorString();
    } else {
    qDebug() << "Retornou: " << reply->readAll();
    }
    }
    ´´´

    Still getting erros.
    Anyone?


  • Lifetime Qt Champion

    Hi,

    You are creating a new QNetworkAccessManager each time you call sendRequest and never delete it, the same goes for the QNetworkReply.

    You should have only one QNetworkAccessManager for your application and take care of cleaning up the QNetworkReply.



  • I try to do that I got another errors.
    I will check this again, I try to clear and remove the reference and etc... But I don't found anything about it.

    I will try more!

    Thanks



  • @SGaist

    Well I use 3 QNetworkAccessManager and 1 QTcpSocket:

    1. Check Internet Connection (With google), checked every second;
    2. Check Server Connection, checked every second too;
    3. The main: Send data received from QTcpSocket (I read data from another App thru TCP Socket).

    So, appears to be an error on item 3. After start send data do server I get the crash, so...

    • I change all QNetworkAccessManager to use each one single Instance (can I call Instance in C/C++) and this change:
    void RestServices::slotRequestFinished(QNetworkReply *reply)
    {
        reply->close();
        delete myManager;
    }
    

    So each "send" create a new myManager and after send DELETE it...
    Appears more stable (for longer) at this moment. I will need test more.



  • Yeap... The app take longerrrrr to crash, but I got same error...


  • Lifetime Qt Champion

    You can use a single QNetworkAccessManager for your application. It will handle parallel connections for you (up to six at the same time and it will queue other requests made IIRC)



  • @SGaist I can instantiate on MainWindow, at start up and pass the pointer to other classes, that's correct?
    And I can make any connection withs signals to handle each request that I make?


  • Lifetime Qt Champion

    You can yes.

    Since you are making a REST service interface. You should rather have an object that represent that service and have your widgets call functions on that object. That way you can modify the REST service if you want and only have one place in your code that you will need to modify.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.