Question

I'd like to ask you a question. I'm writting an application in QT Designer and I made a kind of web browser. I have two radio buttons. If the first one is checked - page index.html is loaded normally to my QWebView. I'm using this:

string url = sDir + ui->pageComboBox->currentText().toStdString() + ".html";
ui->logView->load(QUrl::fromLocalFile(QDir::cleanPath(QDir::current().absoluteFilePath(QString::fromStdString(url)))));

It's working fine. But I give user a second option of loading page - if the second radio button is checked then it activates a DateEdit and user have to pick a date. Chosen date is stored in QString. Now, I'd like to load the same page scrolled down to this date:

string url = sDir + ui->pageComboBox->currentText().toStdString() + ".html" + showAt.toStdString();
ui->logView->load(QUrl::fromLocalFile(QDir::cleanPath(QDir::current().absoluteFilePath(QString::fromStdString(url)))));

So, the requested site link is something like this: index.html#29082013. Here it's not working, no site is loaded :( Still have blank page. I added tags in html file, so for example in Google Chrome it's working fine. What am I doing wrong? Could you help me? Thanks..

Was it helpful?

Solution

When you do this:

QDir::current().absoluteFilePath(QString::fromStdString(url))

You are asking QDir (that doesn't know what an url is), to get the filepath of the file index.html#29082013, which of course doesn't exist.

The solution is to first get the filepath from index.html, then get an url from it, and only then add the hash #29082013. Try this:

QString filename = QString(sDir) + ui->pageComboBox->currentText() + ".html";
QUrl urlWithoutHash = QUrl::fromLocalFile(QDir::current().absoluteFilePath(filename));
ui->logView->load(urlWithoutHash.toString() + showAt);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top