For loop in button for sending url freeze app



  • Ok so,I try to do for a friend a bot applications that will automatically open a few links in the right order with the right settings. The problem is that when the law send a link 1 x times x second intervals entire application freeez. For small numbers of what i could check everything is done correctly and after the set time application hangs up. However, the need to remain logged and probably too long Freez will log
    The short code jst with the one button and this loop...

    #include "mainwindow.h"
    #include "ui_mainwindow.h" 
    #include <QThread>
    #include <QMessageBox>
    #include <QtNetwork>
    
    class Sleeper : public QThread
    {
    public:
        static void usleep(unsigned long usecs){QThread::usleep(usecs);}
        static void msleep(unsigned long msecs){QThread::msleep(msecs);}
        static void sleep(unsigned long secs){QThread::sleep(secs);}
    };
    
    void MainWindow::on_pushButton_6_clicked()
    {
        if(ui->checkBox->isChecked()){
            QMessageBox::information(this,"test",ui->spinBox->text()); //just for test, here comes another link
        }
        for( int i=0; i<ui->spinBox->value(); ++i )
        {
        ui->webView->load(QUrl("http://google.pl"));
        Sleeper::sleep(1);
        }
    }
    

    Is ther any way to not freez gui? I;m totaly newbie in qt and C++ programing so i can;t resove is by myself :S



  • @Vizi Maybe using QTimer and signals/slots.



  • the point is i i;m totaly newbie, I saw on a some guide gthat threads can run in background w/o lagging the application, it;s possible do this loop on thread?




Log in to reply
 

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