Creating QActions on the fly for history
-
You are probably creating a loop
Why are you creating numRecentHistory actions each time you call addToHistory ?
-
What would be a better way to do it?
-
Like I said, follow the Recent File Example, it shows how to handle that
-
I have tried to follow that example, and based on it thats what I have so far.
How is it creating a loop and how do I fix it? -
You're code doesn't reflect the example, you are creating each time numRecentHistory actions.
The best way to see where the problem lies is to run your application through the debugger
-
As in 'debug' vs 'release' when i hit the run button?
-
Would having numRecentHistory outside of the function so it isn't created every time be better?
-
As in use the button with a little bug on it with a debug build of your application
-
Okay now if I click on one one of the historyActions, nothing happens. It doesn't load the page, crash, or anything.
Code:
@void browseTab::addToHistory()
{
QString url = webView->url().toString();QString historyEntry = url; QString title = webView->title(); QIcon icon = webView->icon(); int numRecentHistory = 1; for (int i = 0; i < numRecentHistory; ++i) { 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)));
}
@ -
Okay I restarted Qt and now it crashes again like it has been. I ran the debugger and it seemed to have an issue with the following code:
@loadHistory(action->data().toString());@How can I fix this?
Thanks! I appreciate your help SGaist! -
Sorry to resurrect the thread,
I am still having trouble with my application crashing when I click one of the historyActions, I have read the examples provided, and I still don't understand why it crashes. Could someone please help me?
-
If it crashes, the first thing to do is to get out your debugger to figure out where it crashes.