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.
for example when I log in to www.login.com the data of the login show on the same link
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 by press on view source code in firefox the login data appear in the source code
This is 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 on what I should do.
update
I view the page source code from firefox get the text input name and use QUrlQuery to make post to it by the result was the first page without login this the part of HTML code I got the name of it
<label class="label-off" for="dwfrm_ordersignup_orderNo">Numéro de la commande</label> <input class="textinput required" id="anyname" type="text" name="UserName" value="" maxlength="2147483647" placeholder="* UserName" data-missing-error="Saisis ton numéro de commande. " data-parse-error="Ce contenu est invalide" data-range-error="Ce contenu est trop long ou trop court" required="required" />
and it has same code for the other field.
Code for I use in Qt to make a post
manager = new QNetworkAccessManager(this);
QUrlQuery query;
query.addQueryItem("UserName", "AAAA");
query.addQueryItem("Password", "BBB");
reply = manager->post(QNetworkRequest(QUrl(ui->lineEdit->text().trimmed())), query.toString().toUtf8());
connect(reply,&QNetworkReply::downloadProgress,this,&MainWindow::progress);
connect(reply,SIGNAL(readyRead()),this,SLOT(readyRead()));
connect(reply, SIGNAL(finished()), this,SLOT(finish()));
I try the post code with PHP page I made and it work the problem here it's only HTML page