Qt Disable Not Responding timeout?

0

In my project, I have a lot of loops making many calculations that can take quite some time. Everything runs fine until I get an error while it's loading. When it's calculating everything, my program becomes "Unresponsive" until it is finished loading. It seems there is some sort of timer and when it reaches 60 seconds, the debugging stops and I get this error:

Exception at 0x7585b9bc, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in Qt5Cored!QTimer::isSingleShot

Is there any way to disable that responsiveness timer?

Thanks for your time :)

EDIT: Here is the loop. It's awfully abstract so I apologize that you don't know the full context of this loop. :/ But know this, the program doesn't freeze at the exact same point in time. Sometimes when i== 498, sometimes 499. etc.

   for(int i=0; i<=728; i++)
    {
        int sections;
        if(PCBRchunks[i] != "Null")
        {
            QString blockId;
            PCBRblocks[i].fill('0', 131072);

            //Get number of sections
            temp_hex = PCBRchunks[i].mid(PCBRchunks[i].indexOf("09000853656374696f6e73")+30, 2);
            HexToInt2(temp_hex, temp_int);
            sections = temp_int;

            int totalStart;
            totalStart = PCBRchunks[i].indexOf("070006426c6f636b7300001000")+26;

            for(int s=0; s<=sections-1; s++)
            {
                int y;
                temp_hex = PCBRchunks[i].mid(totalStart + (s*20604) + 20574, 2);
                HexToInt2(temp_hex, y);

                for(int k=0; k<=255; k++)
                {
                    for(int p=0; p<=15; p++)
                    {
                        blockId = PCBRchunks[i].mid(totalStart + (s*20604) + (p*512) + ((((k-((k/16)*16))*16)+(k/16))*2), 2);
                        if(y<8)
                            PCBRblocks[i].replace((p*2)+(k*256)+(y*32), 2, blockId);
                        else
                            PCBRblocks[i].replace((p*2)+(k*256)+((y-8)*32)+65536, 2, blockId);
                    }
                }
            }
        }

        if(PCBLchunks[i] != "Null")
        {
            QString blockId;
            PCBLblocks[i].fill('0', 131072);

            //Get number of sections
            temp_hex = PCBLchunks[i].mid(PCBLchunks[i].indexOf("09000853656374696f6e73")+30, 2);
            HexToInt2(temp_hex, temp_int);
            sections = temp_int;

            int totalStart;
            totalStart = PCBLchunks[i].indexOf("070006426c6f636b7300001000")+26;

            for(int s=0; s<=sections-1; s++)
            {
                int y;
                temp_hex = PCBLchunks[i].mid(totalStart + (s*20604) + 20574, 2);
                HexToInt2(temp_hex, y);

                for(int k=0; k<=255; k++)
                {
                    for(int p=0; p<=15; p++)
                    {
                        blockId = PCBLchunks[i].mid(totalStart + (s*20604) + (p*512) + ((((k-((k/16)*16))*16)+(k/16))*2), 2);
                        if(y<8)
                            PCBLblocks[i].replace((p*2)+(k*256)+(y*32), 2, blockId);
                        else
                            PCBLblocks[i].replace((p*2)+(k*256)+((y-8)*32)+65536, 2, blockId);
                    }
                }
            }
        }
        if(PCTRchunks[i] != "Null")
        {
            QString blockId;
            PCTRblocks[i].fill('0', 131072);

            //Get number of sections
            temp_hex = PCTRchunks[i].mid(PCTRchunks[i].indexOf("09000853656374696f6e73")+30, 2);
            HexToInt2(temp_hex, temp_int);
            sections = temp_int;

            int totalStart;
            totalStart = PCTRchunks[i].indexOf("070006426c6f636b7300001000")+26;

            for(int s=0; s<=sections-1; s++)
            {
                int y;
                temp_hex = PCTRchunks[i].mid(totalStart + (s*20604) + 20574, 2);
                HexToInt2(temp_hex, y);

                for(int k=0; k<=255; k++)
                {
                    for(int p=0; p<=15; p++)
                    {
                        blockId = PCTRchunks[i].mid(totalStart + (s*20604) + (p*512) + ((((k-((k/16)*16))*16)+(k/16))*2), 2);
                        if(y<8)
                            PCTRblocks[i].replace((p*2)+(k*256)+(y*32), 2, blockId);
                        else
                            PCTRblocks[i].replace((p*2)+(k*256)+((y-8)*32)+65536, 2, blockId);
                    }
                }
            }
        }
        if(PCTLchunks[i] != "Null")
        {
            QString blockId;
            PCTLblocks[i].fill('0', 131072);

            //Get number of sections
            temp_hex = PCTLchunks[i].mid(PCTLchunks[i].indexOf("09000853656374696f6e73")+30, 2);
            HexToInt2(temp_hex, temp_int);
            sections = temp_int;

            int totalStart;
            totalStart = PCTLchunks[i].indexOf("070006426c6f636b7300001000")+26;

            for(int s=0; s<=sections-1; s++)
            {
                int y;
                temp_hex = PCTLchunks[i].mid(totalStart + (s*20604) + 20574, 2);
                HexToInt2(temp_hex, y);

                for(int k=0; k<=255; k++)
                {
                    for(int p=0; p<=15; p++)
                    {
                        blockId = PCTLchunks[i].mid(totalStart + (s*20604) + (p*512) + ((((k-((k/16)*16))*16)+(k/16))*2), 2);
                        if(y<8)
                            PCTLblocks[i].replace((p*2)+(k*256)+(y*32), 2, blockId);
                        else
                            PCTLblocks[i].replace((p*2)+(k*256)+((y-8)*32)+65536, 2, blockId);
                    }
                }
            }
        }
        qDebug() << i;
        ui->progressBar->setValue((i*100)/729);
    }
c++
qt
loops
timeout
asked on Stack Overflow Sep 7, 2013 by mrg95 • edited Jan 21, 2014 by Kara

2 Answers

2

I think it's not within Qt, it's in the operating system. The best solution is to perform your work in a worker thread so that UI thread can process messages in the meantime.

answered on Stack Overflow Sep 7, 2013 by Violet Giraffe • edited Nov 16, 2013 by Violet Giraffe
1

It is a general practice to establish worker threads for heavy computations not to get the UI unresponsive. The worker thread would be decoupled from the main ui thread for that reason.

Here you can find an article with very complete explanation and examples how to create a thread class in general, even though you could use std::thread with C++11:

http://www.codeproject.com/Articles/21114/Creating-a-C-Thread-Class

Here you can find an article with very complete explanation and examples how to create worker threads:

http://www.codeproject.com/Articles/552/Using-Worker-Threads

Hope, it helps.

answered on Stack Overflow Sep 7, 2013 by lpapp

User contributions licensed under CC BY-SA 3.0