[Interest] QWinEventNotifier: Cannot have more than 62 enabled at one time

Jason Kretzer Jason at gocodigo.com
Fri Aug 15 17:55:49 CEST 2014


Good Day!

I have the below code.  Somewhere between the end of the start function and the beginning of the disconnected function I am getting the warning in the subject line.  In the below code, “ContentProcess” inherits QProcess, I just added a some string data to keep with it.  Also, fprocessHash is a QHash that I use to keep track of all open fprocesses.

Anyway, the code is supposed to run like this:  It receives a command on the port 9000, the command gives it the parameters for running a ContentProcess.  The ContentProcess has the “error” and “finished” signals connected to appropriate slots.  In the case of error, it is connected the “restartFProcess” slot in which the fprocess is disconnected, closed, and deleted.  It is also removed from the hash.  Then a new ContentProcess is instantiated, it is then reconnected with the above signals/slots, added to the hash, and started again.  The finished signal is caught by the DeleteFProcess slot.  There it is just removed from the hash, and DeleteLater is called.

The fprocessHash is used to keep track of all the running fprocesses.  If a “Kill” order comes in as a command, the killallFprocesses function is called.  The hash is iterated through, all found fprocesses are removed from the hash, disconnected, closed, and deleted.

In my logs, after about 440 or so of the processes have run and dutifully deleted by the DeleteFProcess function after they finished, I get the eror in the subject line.

Any thoughts?  I believe that I am policing everything and have never run into this error before.

-Jason


//=============================//

#include "mainwindow.h"
static inline qint32 ArrayToInt(QByteArray source);

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
    strData="";
    index = 0;

    // ====== TCP SERVER CODE ======

    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), SLOT(newConnection()));
    connect(this,SIGNAL(dataReceived(QByteArray)), this, SLOT(getData(QByteArray)));
    qDebug() << "Listening:" << server->listen(QHostAddress::Any, 9000);

}

MainWindow::~MainWindow()
{}

void MainWindow::start(QString filename, QString params, bool stretch, int t, int x1, int y1, int x2, int y2)
{

    ContentProcess *fprocess = new ContentProcess();
    fprocess->setStartTime(QDateTime::currentMSecsSinceEpoch());

    QStringList arguments;
    arguments << filename << params << QString(stretch ? "true" : "false")
         << QString::number(x1) << QString::number(y1) << QString::number(x2) << QString::number(y2)
       << QString::number(t);
    fprocess->setArguments(arguments);
    qDebug() << "PROCESS ARGS= [\n" << arguments << "\n]";
    fprocess->setProgram("fprocess.exe");
    fprocess->setObjectName(QString::number(index));
    qDebug() << "Adding new fprocess to the list of fprocessHash -- index: " << index;
    fprocessHash.insert(index,fprocess);
    index++;

    connect(fprocess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(restartFProcess(QProcess::ProcessError)));
    connect(fprocess, SIGNAL(finished(int)), this, SLOT(deleteFProcess()));

    fprocess->start();
}

void MainWindow::restartFProcess(QProcess::ProcessError err)
{
    ContentProcess *fprocess = static_cast<ContentProcess*>(sender());

    QStringList procargs = fprocess->arguments();

    qDebug() << "\nERROR DETECTED -- CODE: " << err;
    qDebug() << "Process: " << procargs.first();
    qDebug() << "Start: " << fprocess->getStartTime();
    qDebug() << "Curr Time: " << QDateTime::currentMSecsSinceEpoch();

    qDebug() << "Disconnecting the error signal";
    fprocess->disconnect();

    qDebug() << "KILLING";
    fprocess->close();

    fprocessHash.remove(fprocess->objectName().toInt());
    qDebug() << "Deleting fprocess from error -- index: " << fprocess->objectName();

    delete fprocess;
    fprocess = 0;
    fprocess = new ContentProcess();

    int oldt = procargs.last().toInt();
    int newt = oldt - ((int)(QDateTime::currentMSecsSinceEpoch() - fprocess->getStartTime()));
    procargs.removeLast();
    procargs << QString::number(newt);

    fprocess->setArguments(procargs);

    qDebug() << "PROCESS ARGS= [\n" << procargs << "\n]";
    fprocess->setProgram("fprocess.exe");

    qDebug() << "RESTARTING";

    qDebug() << "Starting new fprocess from error -- index: " << fprocess->objectName();
    fprocess->setObjectName(QString::number(index));
    fprocessHash.insert(index, fprocess);
    index++;

    connect(fprocess, SIGNAL(error(QProcess::ProcessError)),this, SLOT(restartFProcess(QProcess::ProcessError)));
    connect(fprocess, SIGNAL(finished(int)), this, SLOT(deleteFProcess()));

    fprocess->start();
}

void MainWindow::deleteFProcess()
{
    ContentProcess *fprocess = static_cast<ContentProcess*>(sender());
    fprocessHash.remove(fprocess->objectName().toInt());
    qDebug() << "Deleting fprocess from slot -- index: " << fprocess->objectName();
    fprocess->deleteLater();
}

void MainWindow::killAllFprocesses()
{
    foreach(ContentProcess *fproc, fprocessHash) {
        qDebug() << "Deleting fprocess from killall order -- index: " << fproc->objectName();
        int ind = fproc->objectName().toInt();
        fprocessHash.remove(ind);
        fproc->disconnect();
        fproc->close();
        fproc->deleteLater();
    }
}

void MainWindow::newConnection()
{
    qDebug() << "\n\n========new Connection=========";
    while (server->hasPendingConnections())
    {
        QTcpSocket *socket = server->nextPendingConnection();
        connect(socket, SIGNAL(readyRead()), SLOT(readyRead()));
        connect(socket, SIGNAL(disconnected()), SLOT(disconnected()));
        QByteArray *buffer = new QByteArray();
        qint32 *s = new qint32(0);
        buffers.insert(socket, buffer);
        sizes.insert(socket, s);
    }
}
void MainWindow::disconnected()
{
    qDebug() << "\n========End Connection=========\n\n";
    QTcpSocket *socket = static_cast<QTcpSocket*>(sender());
    QByteArray *buffer = buffers.value(socket);
    qint32 *s = sizes.value(socket);
    buffers.remove(socket);
    sizes.remove(socket);
    socket->deleteLater();
    delete buffer;
    delete s;    
}

void MainWindow::readyRead()
{
    QTcpSocket *socket = static_cast<QTcpSocket*>(sender());
    QByteArray *buffer = buffers.value(socket);
    qint32 *s = sizes.value(socket);
    qint32 size = *s;
    while (socket->bytesAvailable() > 0)
    {
        buffer->append(socket->readAll());

        while ((size == 0 && buffer->size() >= 4) || (size > 0 && buffer->size() >= size)) //While can process data, process it
        {
            if (size == 0 && buffer->size() >= 4) //if size of data has received completely, then store it on our global variable
            {
                size = ArrayToInt(buffer->mid(0, 4));
                *s = size;
                buffer->remove(0, 4);
            }
            if (size > 0 && buffer->size() >= size) // If data has received completely, then emit our SIGNAL with the data
            {
                QByteArray data = buffer->mid(0, size);
                buffer->remove(0, size);
                size = 0;
                *s = size;
                emit dataReceived(data);
            }
        }

    }
}

void MainWindow::getData(QByteArray data){
    strData = data;
    qDebug() <<"getData:  " << strData;
    QString fileName="";
    QString params="";
    QString stretch="";
    int x1=0;
    int y1=0;
    int x2=0;
    int y2=0;
    int t=0;

    QStringList strList = strData.split("#");
    qDebug ()<<" length strList "<<strList.length();
    if(strList.length() == 1) {
        if(strList.first().compare("KILL", Qt::CaseSensitive) == 0) {
            qDebug() << "Received the kill flash order";
            this->killAllFprocesses();
            return;
        }
    }
    for(int i=0;i< strList.length();i++){
        qDebug ()<<strList.value(i);
    }
    if(strList.length()<=8){
        fileName = strList.value(0);
        params  = strList.value(1);
        stretch = strList.value(2);
        x1 =strList.value(3).toInt();
        y1 =strList.value(4).toInt();
        x2 = strList.value(5).toInt();
        y2 = strList.value(6).toInt();
        t = strList.value(7).toInt();
    }

    QFile f(fileName);
    if(f.exists()) {
        qDebug() << "file exist";
    }
    this->start(fileName,params,(stretch.compare("true", Qt::CaseInsensitive) == 0),t, x1, y1, x2, y2);
}

qint32 ArrayToInt(QByteArray source)
{
    qint32 temp;
    QDataStream data(&source, QIODevice::ReadWrite);
    data >> temp;
    return temp;
}
//=============================//



More information about the Interest mailing list