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. Downloading website content
Qt 6.11 is out! See what's new in the release blog

Downloading website content

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views 1 Watching
  • 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 have a problem with downloading the website content. I just want to make the program downloaded from the content "<span class="file-icon1 archive"> text </ span>" and display it in the program.

    When you compile the code pop up such errors:
    @D:\qt\sprawdz_linki\mainwindow.cpp:-1: In member function 'void MainWindow::finished(bool)':

    D:\qt\sprawdz_linki\mainwindow.cpp:30: błąd: conversion from 'QWebPage*' to non-scalar type 'QWebElement' requested
    QWebElement elem = qwv->page();
    ^

    D:\qt\sprawdz_linki\mainwindow.cpp:34: błąd: conversion from 'QWebElement' to non-scalar type 'QString' requested
    QString test = elem;
    ^@

    And here is the code of the program:
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    QWebView *qwv = new QWebView();

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

    }

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

    void MainWindow::on_pushButton_clicked()
    {
    QWebView *qwv = new QWebView();
    qwv->setUrl(QUrl("http://download.qt-project.org/official_releases/online_installers/qt-opensource-linux-x64-1.6.0-online.run"));

    connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
    

    }

    void MainWindow::finished(bool)
    {
    QWebElement elem = qwv->page();

    elem.findFirst("span[class=\"file_icon1 archive\"]");
    
    QString test = elem;
    
    ui->label->setText(test);
    

    }
    @

    [andreyc EDIT: Suspicious link was changed]

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      The error messages are pretty clear: you are performing an invalid conversion.

      Try this code instead:
      @
      QWebElement elem = qwv->page()->mainFrame()->findFirstElement("span class=\“file-icon1 archive\”");
      QString test = elem.toPlainText();
      @

      Or something similar.

      (Z(:^

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maniek1310
        wrote on last edited by
        #3

        Images:
        http://pics.tinypic.pl/i/00528/3xv7pbe9l8o7.png
        Error :
        @QWidget: Must construct a QApplication before a QWidget@

        Code :
        @#include "mainwindow.h"
        #include "ui_mainwindow.h"

        QWebView *qwv = new QWebView();

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

        }

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

        void MainWindow::on_pushButton_clicked()
        {
        QWebView *qwv = new QWebView();
        qwv->setUrl(QUrl("http://download.qt-project.org/official_releases/online_installers/qt-opensource-linux-x64-1.6.0-online.run"));

        connect(qwv, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
        

        }

        void MainWindow::finished(bool)
        {
        //QWebElement elem = qwv->page();

        //elem.findFirst("span[class=\"file_icon1 archive\"]");
        
        //QString test = elem;
        
        QWebElement elem = qwv->page()->mainFrame()->findFirstElement("span class=\"file-icon1 archive\"");
        QString test = elem.toPlainText();
        
        ui->label->setText(test);
        

        }
        @

        @#ifndef MAINWINDOW_H
        #define MAINWINDOW_H

        #include <QMainWindow>
        #include <QUrl>
        #include <QtWebKitWidgets/QWebView>
        #include <QtWebKit/QWebElement>
        #include <QWebElementCollection>
        #include <Qstring>
        #include <QWebFrame>

        namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

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

        private slots:
        void on_pushButton_clicked();
        void finished(bool);

        private:
        Ui::MainWindow *ui;
        };

        #endif // MAINWINDOW_H
        @

        [URL=http://www.tinypic.pl/3xv7pbe9l8o7][IMG]http://pics.tinypic.pl/i/00528/3xv7pbe9l8o7_t.jpg[/IMG][/URL]

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maniek1310
          wrote on last edited by
          #4

          Already fixed the error. The program starts correctly, but when you click on the button does not charge content <span class="file-icon1 archive">

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maniek1310
            wrote on last edited by
            #5

            Could someone help me

            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