Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved For loop in button for sending url freeze app

    Qt WebKit
    2
    4
    1146
    Loading More Posts
    • 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.
    • V
      Vizi last edited by Vizi

      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

      R 1 Reply Last reply Reply Quote 0
      • R
        raf924 @Vizi last edited by

        @Vizi Maybe using QTimer and signals/slots.

        1 Reply Last reply Reply Quote 0
        • V
          Vizi last edited by

          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?

          R 1 Reply Last reply Reply Quote 0
          • R
            raf924 @Vizi last edited by

            @Vizi See there: http://doc.qt.io/qt-5/qthread.html#details

            1 Reply Last reply Reply Quote 0
            • First post
              Last post