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. QWebView - checking several links
QtWS25 Last Chance

QWebView - checking several links

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    maniek1310
    wrote on last edited by
    #1

    Hi, I wrote a program that checks if the link is correct. All shows correctly only when I throw a few links there is a problem and checks only one link (the last). Below throw program code:

    mainwindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QUrl>
    #include <Qstring>
    #include <QWebFrame>
    #include <QWebView>
    #include <QWebElement>
    #include <QWebElementCollection>
    #include <QDebug>
    #include <string>
    #include <QTableWidgetItem>
    #include <QHeaderView>
    #include <sstream>

    using namespace std;

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    QWebView *qwv = new QWebView();
    ~MainWindow();

    private slots:
    void lnk_turbobit();
    void lnk_rapidgator();
    void lnk_catshare();
    void on_pushButton_clicked();
    void finished(bool);

    private:
    Ui::MainWindow *ui;
    QUrl lnk;
    unsigned int licznik = -1;
    unsigned int width = 0;
    unsigned int width2 = 0;
    };

    #endif // MAINWINDOW_H
    @

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "load.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_pushButton_clicked()
    {
    QString rep_lnk = ui->textEdit->toPlainText();
    string buffor;
    istringstream is(rep_lnk.toStdString());

    unsigned int j = 0;
    
    while(getline(is, buffor))
    {
    
        QString rep_lnk2 = buffor.c_str();
    
        rep_lnk2.replace(" ", "");
        rep_lnk2.replace("\n", "");
    
    
        qDebug() << rep_lnk2;
    
        lnk = rep_lnk2;
    
        qwv->setUrl(lnk);
    
        ui->label->setText("Sprawdzanie linków");
    
        connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
    }
    
    licznik ++;
    

    }

    void MainWindow::finished(bool)
    {

    ui->label->setText("Zakończono sprawdzanie linków");
    
    QString file;
    unsigned int n;
    
    file = lnk.toString();
    
    n = file.toStdString().find("turbobit");
    if(n != string::npos)
        lnk_turbobit();
    
    n = file.toStdString().find("rapidgator");
    if(n != string::npos)
        lnk_rapidgator();
    
    n = file.toStdString().find("catshare");
    if(n != string::npos)
        lnk_catshare();
    
    
    //lnk_turbobit();
    //lnk_rapidgator();
    //lnk_catshare();
    

    }

    ...
    @

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

      Hi,

      @
      while(getline(is, buffor))
      {

          QString rep_lnk2 = buffor.c_str();
      
          rep_lnk2.replace(" ", "");
          rep_lnk2.replace("\n", "");
      
      
          qDebug() << rep_lnk2;
      
          lnk = rep_lnk2;
      
          qwv->setUrl(lnk);
      
          ui->label->setText("Sprawdzanie linków");
      
          connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
      }
      

      @

      In this loop you don't wait for the loading to end and replace the current url on each iteration.

      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
      • M Offline
        M Offline
        maniek1310
        wrote on last edited by
        #3

        That's how it is. Only now just do not know how to do to be waiting at the end of each link.

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

          There are several possibilities one being to use signals and slots and a singleShot QTimer when the loading has finished

          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