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. Get containts of website from QWebView using Qt 5.5.1

Get containts of website from QWebView using Qt 5.5.1

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 590 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    Hello
    I'm using Qt 5.5.1 and I make a small browser using QWebview I want when I open a web page and press a button, it get the content of the website like I use get method in QnetworkAccessManager without using it because I want to get the data from website that have a login page so the URL not change when I log in and have not post method to PHP to get the data
    I need any idea I can solve this problem or if I can get the current data from website open in the QWebview
    Note
    when I login into the website and get the data from it and press on view source code in firefox the data appear in the source code
    Thanks in Advance

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      When you login on the page your session data is stored. As long as you use the same session you can access the page however you want, including using get(). It's only important that you use the same instance of QNetworkAccessManager that you used to login and not create a new one. You can get that instance using networkAccessManager() member of the page.
      If, for whatever reason, you want to use another instance (there's usually no good reason to do that) it's important to use the same cookie jar to store the session data. Use cookieJar() and setCookieJar() to share cookies between instances of QNAM.

      1 Reply Last reply
      0
      • AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        @Chris-Kawa Thanks for this hint and this what i tried

        MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
        {
          ui->setupUi(this);
          ui->webView->load(QUrl("https://www.login.com")); // load page that have user name and password field
          QWebPage *page = ui->webView->page(); // get the current page 
          manager = page->networkAccessManager(); // get the access manager from this page
        }
        
        MainWindow::~MainWindow()
        {
          delete ui;
        }
        // get button
        void MainWindow::on_pushButton_clicked()
        {
          reply = manager->get(QNetworkRequest(QUrl("https://www.login.com"))); // make get now after login
          connect(reply, SIGNAL(readyRead()),this,SLOT(readyRead()));
          connect(reply, SIGNAL(finished()),this, SLOT(finish()));
        }
        
        void MainWindow::readyRead()
        {
          QString str = QString::fromUtf8(reply->readAll()).trimmed(); // read the data
          ui->plainTextEdit->appendPlainText(str);
        }
        
        

        but i get the data of the first page without the login i want to get the page content after login please give me any hint or what i should do
        Thanks

        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