QWeView is empty when going to internal target location



  • Hello everyone. I'm confused. When i go to internal target location then window title QWebView will be empty.
    I don't understand.

    Code:

    **header:**
    
    #include <QWidget>
    #include <QWebPage>
    #include <QWebView>
    class MainWindow : public QWidget
    {
    	Q_OBJECT
    
    public:
    	explicit MainWindow(QUrl url, QWidget *parent = 0);
    
    private slots:
    	void titleChanged(QString);
    private:
    	QWebView webView;
    	QWebPage page;
    };
    **cpp:**
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QWebFrame>
    #include <QPainter>
    #include <QPixmap>
    #include <QPushButton>
    #include <QDebug>
    
    MainWindow::MainWindow(QUrl url, QWidget *parent) :
    	QWidget(parent)
    {
    	page.mainFrame()->load(url);
    	connect(&page, SIGNAL(loadFinished(bool)),
    		this, SLOT(showPage()));
    	connect(page.mainFrame(), SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString)));
    	webView.setPage(&page);
    	webView.show();
    }
    void MainWindow::titleChanged(QString title)
    {
    	QString old_title = page.mainFrame()->title();
    	qDebug() << "\nOld title " << old_title;
    	qDebug() << "\nNew title " << title;
    	webView.setWindowTitle(title);
    }
    
    
    

    For example:

    1. On link text we can see "Contens" if window is small.
    2. Next, open "Contens", and click on first internal target location ("Public types"), we are going other place in current page.
    3. Then emit titleChanged which it is empty. Why???
      Explain please.

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.