Engo Engo - 3 months ago 24
C++ Question

What is causing my first-chance (stack overflow) exception in Qt?

I have a QComboBox which should be updated on CurrentTextChanged. I have created the following connect statement so that the QComboBox fires the onFilterComboBoxCurrentTextChanged slot:

connect(m_viewController->getFilterWindow()->getFilterComboBox(), &QComboBox::currentTextChanged, this, &MainController::onFilterComboBoxCurrentTextChanged);


clearAndAddDICOMTagsToShownTagsListWidget causes the following errors. How can I solve this?

void MainController::onFilterComboBoxCurrentTextChanged(QString filterName)
{
m_viewController->clearAndAddFilterNamesToFilterComboBox(m_fileController->loadFilterNamesFromConfigFile());
}

QStringList FileController::loadFilterNamesFromConfigFile()
{
QSettings settings(QDir::toNativeSeparators("C:\\HelloWorld\\Config\\Filter.cfg"), QSettings::IniFormat);
QStringList filtersNames = settings.childGroups();
return filtersNames;
}

void ViewController::clearAndAddFilterNamesToFilterComboBox(QStringList filterNames)
{
m_filterWindow.getFilterComboBox()->clear();
m_filterWindow.getFilterComboBox()->addItems(filterNames);
}

QListWidget* FilterWindow::getShownTagsListWidget()
{
return ui.shownTagsListWidget;
}



First-chance exception at 0x777EAFC0 (ntdll.dll) in DoseView.exe:
0xC00000FD: Stack overflow (parameters: 0x00000001, 0x002C2FFC).

Unhandled exception at 0x777EAFC0 (ntdll.dll) in DoseView.exe:
0xC00000FD: Stack overflow (parameters: 0x00000001, 0x002C2FFC).


enter image description here

Answer

The easy fix is to block signals before updating combo box's items. Something like this :

void MainController::onFilterComboBoxCurrentTextChanged(QString filterName) {
combobox->blockSignals(true); 
m_viewController->clearAndAddFilterNamesToFilterComboBox(m_fileController->loadFilterNamesFromConfigFile());
combobox->blockSignals(false);
}

But I believe you should be able to prevent it by a better design of your code.

Comments