2012-04-01 4 views
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 시간 동안 문제가있는 곳을 찾았고 아무 것도 볼 수 없었습니다.

답변

2

신호를 생성자에서 가능한 한 한 번만 슬롯에 연결해야합니다.

는 반대로, 당신은 당신이 항목을 변경

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

evety 시간을 호출합니다. 따라서 connect을 호출 할 때마다 슬롯이 여러 번 호출됩니다.

+0

오, 젠장, 나는 그 라인에 대해 완전히 잊어 버렸다. 거의 모든 것을 주석 처리했지만, 이것은. >.> 그런 수치심. 정말 고마워. ;) –

관련 문제