For loop in button for sending url freeze app
-
wrote on 25 Oct 2015, 15:45 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
-
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
-
wrote on 26 Oct 2015, 18:59 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?
-
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?
wrote on 27 Oct 2015, 18:42 last edited by@Vizi See there: http://doc.qt.io/qt-5/qthread.html#details
1/4