Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWinEventNotifier: Cannot have more than 62 enabled at one time
QtWS25 Last Chance

QWinEventNotifier: Cannot have more than 62 enabled at one time

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JasonKretzer
    wrote on last edited by
    #1

    Good Day!

    I have the below code. Somewhere along the line 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 and memory starts filling up. I believe that I am policing everything and have never run into this error before. I had more information but I can only post 6000 characters...

    Any thoughts?

    -Jason

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

    MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
    {
    strData="";
    index = 0;
    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), SLOT(newConnection()));
    connect(this,SIGNAL(dataReceived(QByteArray)), this, SLOT(getData(QByteArray)));
    }

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

    ContentProcess *fp = new ContentProcess();
    fp->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);
    fp->setArguments(arguments);
    fp->setProgram("fp.exe");
    fp->setObjectName(QString::number(index));
    fpHash.insert(index,fp);
    index++;
    connect(fp, SIGNAL(error(QProcess::ProcessError)), this, SLOT(restartFProcess(QProcess::ProcessError)));
    connect(fp, SIGNAL(finished(int)), this, SLOT(deleteFProcess()));
    fp->start();
    }

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

    QStringList procargs = fp->arguments();
    fp->disconnect();
    fp->close();

    fpHash.remove(fp->objectName().toInt());

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

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

    fp->setArguments(procargs);

    fp->setProgram("fp.exe");
    fp->setObjectName(QString::number(index));
    fpHash.insert(index, fp);
    index++;

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

    fp->start();
    }

    void MainWindow::deleteFProcess()
    {
    ContentProcess fp = static_cast<ContentProcess>(sender());
    fpHash.remove(fp->objectName().toInt());
    fp->deleteLater();
    }

    void MainWindow::killAll()
    {
    foreach(ContentProcess *fproc, fpHash) {
    int ind = fproc->objectName().toInt();
    fpHash.remove(ind);
    fproc->disconnect();
    fproc->close();
    fproc->deleteLater();
    }
    }

    void MainWindow::newConnection()
    {
    while (server->hasPendingConnections())
    {
    QTcpSocket *skt = server->nextPendingConnection();
    connect(skt, SIGNAL(readyRead()), SLOT(readyRead()));
    connect(skt, SIGNAL(disconnected()), SLOT(disconnected()));
    QByteArray *bfr = new QByteArray();
    qint32 *s = new qint32(0);
    bfrs.insert(skt, bfr);
    sizes.insert(skt, s);
    }
    }
    void MainWindow::disconnected()
    {
    QTcpSocket skt = static_cast<QTcpSocket>(sender());
    QByteArray *bfr = bfrs.value(skt);
    qint32 *s = sizes.value(skt);
    bfrs.remove(skt);
    sizes.remove(skt);
    skt->deleteLater();
    delete bfr;
    delete s;
    }

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

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

    }
    }

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

    QStringList slst = strData.split("#");
    if(slst.length() == 1) {
    if(slst.first().compare("KILL", Qt::CaseSensitive) == 0) {
    this->killAll();
    return;
    }
    }
    if(slst.length()<=8){
    fileName = slst.value(0);
    params = slst.value(1);
    stretch = slst.value(2);
    x1 =slst.value(3).toInt();
    y1 =slst.value(4).toInt();
    x2 = slst.value(5).toInt();
    y2 = slst.value(6).toInt();
    t = slst.value(7).toInt();
    }

    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;
    }
    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The use of static_cast is wrong in this case, you should use qobject_cast.

      I see you are allocating QByteArrays on the heap which is unusual, why are you doing it like that ?

      Can you show your ContentProcess implementation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JasonKretzer
        wrote on last edited by
        #3

        My apologies, that was part of the extra information that I had to cull to get it down under 6k characters.

        ContentProcess simply extends QProcess and adds an extra couple of data items that I want to keep around. here is the header.

        @
        #ifndef CONTENTPROCESS_H
        #define CONTENTPROCESS_H

        #include <QProcess>

        class ContentProcess : public QProcess
        {
        Q_OBJECT
        public:
        explicit ContentProcess(QObject *parent = 0);
        void setStartTime(qlonglong time) {startTime = time;}
        qlonglong getStartTime() {return startTime;}
        int getDuration() {return duration;}
        void setDuration(int dur) {duration = dur;}

        private:
        qlonglong startTime;
        int duration;

        signals:

        public slots:

        };

        #endif // CONTENTPROCESS_H
        @

        As far as the QByteArrays go, I did not write that particular piece of the code. So, not sure.

        For the casts -- whoops. I meant to change that before posting.

        Thanks for looking!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Looks correct.

          If you have access to it, you should take a look. You rarely need to allocate QByteArray like that.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved