1
在我的應用程序中,我有列表視圖。選擇另一個項目,觸發事件:QtWebPage - loadFinished()多次調用
connect(listView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(item_changed(const QModelIndex &, const QModelIndex &)));
void MainWindow::item_changed(const QModelIndex & current, const QModelIndex & previous)
{
qDebug() << "\n" << "item_changed(), caller: " << sender()->objectName();
if (current.isValid())
{
/*
not so important code
*/
change_query(tokens.join("+"));
}
}
這調用另一個插槽 - change_query()。
void MainWindow::change_query(QString newquery)
{
qDebug() << "change_query(), caller: " << sender()->objectName();
QUrl query (newquery);
frame->load(query);
connect(frame, SIGNAL(loadFinished(bool)), this, SLOT(loading_finished()));
}
最後,當頁面完全加載,它應該調用loading_finished()
void MainWindow::loading_finished()
{
qDebug() << "loading_finished(), caller: " << sender()->objectName();
}
但是,令我驚訝的是,輸出是:
item_changed(), caller: "SelectionModel"
change_query(), caller: "SelectionModel"
loading_finished(), caller: "frame"
item_changed(), caller: "SelectionModel"
change_query(), caller: "SelectionModel"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
item_changed(), caller: "SelectionModel"
change_query(), caller: "SelectionModel"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
item_changed(), caller: "SelectionModel"
change_query(), caller: "SelectionModel"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
loading_finished(), caller: "frame"
正如你所看到的,每當我改變選擇時,WebFrame的另一個實例(?)被創建並加載,或者每個循環加載頁面+1次。我花了2個小時查明問題所在,我什麼也沒看到。
哦,該死的,我完全忘記了那條線。幾乎所有的東西都註釋掉了,但是這個。 >>這樣的恥辱。萬分感謝。 ;) – 2012-04-01 17:32:24