Trouble getting history to work



  • Hey everyone,

    I am still having trouble getting the history on my web browser to work right.
    I have 3 slots: addToHistory(), goToHistoryURL(), and loadHistory(). addToHistory is called when the webView loads a page, it creates a new QAction called historyAction which is added to a QMenu called historyMenu. This creates a list of history entries. When one of the historyActions is clicked, it calls goToHistoryURL(). goToHistoryURL() determines which historyAction has been clicked and calls loadURL(). loadURL() in turn sets the webView to the URL of whichever historyAction was clicked. The problem lies in when I click on one of the generated historyAction, it makes my application freeze and crash. How can I fix this? here is my code:

    @
    //adds a URL to history, called whenever webView finishes loading.
    void browseTab::addToHistory()
    {
    QString url = webView->url().toString();

    QString historyEntry = url;
    
    QString title = webView->title();
    
    QIcon icon = webView->icon();
    
        QString text = tr("&%1").arg(title);
    
        historyAction = new QAction(this);
        historyAction->setText(text);
        historyAction->setData(historyEntry);
        historyAction->setIcon(webView->icon());
        historyAction->setIconVisibleInMenu(true);
        HistoryMenu->addAction(historyAction);
        connect(historyAction, SIGNAL(triggered()), SLOT(goToHistoryURL()));
    

    }

    //determines which historyAction has been clicked, calls loadHistory().
    void browseTab::goToHistoryURL()
    {
    QAction *action = qobject_cast<QAction *>(sender());
    if (action)
    loadHistory(action->data().toString());
    }

    //sets the webView to the historyAction's url, called by goToHistoryURL().
    void browseTab::loadHistory(const QString &name)
    {
    webView->setUrl(QUrl(QString(name)));
    }

    @

    Code solution examples would be great!

    Thanks for your time!



  • Any ideas? This is kinda my largest roadblock thus far



  • how can I fix my code?


Log in to reply
 

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