Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 多次调用QtWebPage-loadFinished()_C++_Qt_Qtwebkit - Fatal编程技术网

C++ 多次调用QtWebPage-loadFinished()

C++ 多次调用QtWebPage-loadFinished(),c++,qt,qtwebkit,C++,Qt,Qtwebkit,在我的应用程序中,我有列表视图。选择其中的另一项会触发一个事件: connect(listView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(item_changed(const QModelIndex &, const QModelIndex &))); void MainWindow::item_chan

在我的应用程序中,我有列表视图。选择其中的另一项会触发一个事件:

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("+"));
    }
}

如您所见,每次我更改选择时,都会创建并加载另一个WebFrame实例(?),或者每次循环加载页面+1次。我花了2个小时找出了问题所在,但我什么也没看到。

您应该只将信号连接到插槽一次,在构造函数中是可能的

相反,你打电话

connect(frame, SIGNAL(loadFinished(bool)), this, SLOT(loading_finished()));

每次更换物品时。所以,你的插槽被调用了很多次,就像你调用
connect

哦,该死,我完全忘了那一行。几乎所有内容都被注释掉了,但这个除外。>>真可惜。非常感谢你
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" 
connect(frame, SIGNAL(loadFinished(bool)), this, SLOT(loading_finished()));