Qt signal slots, casting type in the new notation

Given the following two:

connect(ui->comboBox, SIGNAL(activated(QString)), ps, SLOT(requestPlotsAvailable(QString))); connect(ui->comboBox, &QComboBox::activated, ps, &PlotSystem::requestPlotsAvailable); 

The first uses the old notation, which works. The second uses a new notation and gives an error

 error: no matching function for call to 'PlotSystemGui::connect(QComboBox*&, <unresolved overloaded function type>)' 

How to avoid errors using the new notation?

+5
source share
1 answer

This should work

 connect(ui->comboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated), ps, &PlotSystem::requestPlotsAvailable); 

See this question on pointers to overloaded functions.

+8
source

Source: https://habr.com/ru/post/1213182/


All Articles